Skip to content

Commit a8b48c3

Browse files
committed
fix: remove return types "string | None"
Fixes: #31
1 parent 32a15f9 commit a8b48c3

File tree

7 files changed

+32
-61
lines changed

7 files changed

+32
-61
lines changed

examples/doit/doit/cli.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Garcia
1+
# Copyright 2019-2024 Flavio Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -21,14 +21,9 @@
2121

2222
logger = logging.getLogger(__name__)
2323

24-
conf = {
25-
'commands': []
26-
}
27-
2824
DOIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
2925
DOIT_CONFIG_FILE = os.path.join(DOIT_ROOT, "doit", "doit.yml")
3026

31-
3227
pass_context = click.make_pass_decorator(taskio.CliContext, ensure=True)
3328

3429

examples/doit/doit/commands.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Garcia
1+
# Copyright 2019-2024 Flavio Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -27,9 +27,9 @@ def task_function(cmd, namespace):
2727
@taskio.command(short_help="Generates an uuid4 string")
2828
@click.argument("path", required=False, type=click.Path(resolve_path=True))
2929
@pass_context
30-
def uuid(ctx):
31-
"""Initializes a repository."""
32-
print(ctx)
30+
def uuid(ctx, path):
31+
from pprint import pprint
32+
pprint(ctx.context.invoked_subcommand)
3333

3434

3535
@click.command(short_help="Do another thing")

examples/doit/doit/new_commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Gonçalves Garcia
1+
# Copyright 2019-2024 Flavio Gonçalves Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
import click
1717

1818

19-
@click.command()
19+
@click.command(short_help="Do a cli thingy")
2020
@pass_context
2121
def cli1(ctx):
2222
print(ctx.context.loader.sources)

taskio/core.py

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Garcia
1+
# Copyright 2019-2024 Flavio Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,43 +11,18 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
import sys
1514

1615
from . import process
1716
import click
1817
from click.core import Command, Context, Group, HelpFormatter
1918
import typing as t
20-
from typing import Any, Callable, Dict, List, Optional
19+
from typing import Any, Callable, List, Optional
20+
import sys
2121

2222

2323
class TaskioContext(Context):
2424

25-
def __init__(
26-
self,
27-
command: Command,
28-
parent: Optional[Context] = None,
29-
info_name: Optional[str] = None,
30-
obj: Optional[Any] = None,
31-
auto_envvar_prefix: Optional[str] = None,
32-
default_map: Optional[Dict[str, Any]] = None,
33-
terminal_width: Optional[int] = None,
34-
max_content_width: Optional[int] = None,
35-
resilient_parsing: bool = False,
36-
allow_extra_args: Optional[bool] = None,
37-
allow_interspersed_args: Optional[bool] = None,
38-
ignore_unknown_options: Optional[bool] = None,
39-
help_option_names: Optional[List[str]] = None,
40-
token_normalize_func: Optional[Callable[[str], str]] = None,
41-
color: Optional[bool] = None,
42-
show_default: Optional[bool] = None,
43-
) -> None:
44-
super().__init__(command, parent, info_name, obj, auto_envvar_prefix,
45-
default_map, terminal_width, max_content_width,
46-
resilient_parsing, allow_extra_args,
47-
allow_interspersed_args, ignore_unknown_options,
48-
help_option_names, token_normalize_func, color,
49-
show_default)
50-
self.loader = None
25+
loader: process.TaskioLoader
5126

5227

5328
class TaskioRootGroup(Group):

taskio/process.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Garcia
1+
# Copyright 2019-2024 Flavio Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -11,37 +11,40 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
15+
1416

1517
from .config import resolve_reference
16-
from . import core
1718
from cartola import sysexits
1819
import importlib
1920
import logging
2021
import sys
22+
import typing
2123

24+
if typing.TYPE_CHECKING:
25+
from core import TaskioRootGroup
2226

2327
logger = logging.getLogger(__name__)
2428

2529

2630
class TaskioLoader(object):
2731

2832
_conf: dict
29-
_description: str | None
30-
_name: str | None
33+
_description: str
34+
_name: str
3135
_root: str
32-
_program: "core.TaskioRootGroup"
36+
_program: TaskioRootGroup
3337
_sources: list
34-
_version: str | None
38+
_version: str
3539

36-
def __init__(self, conf, program=None, **kwargs):
40+
def __init__(self, conf, program: TaskioRootGroup = None, **kwargs):
3741
self._conf = conf
3842
self._root = kwargs.get("root", "taskio")
3943
self._program = program
4044
self._sources = []
4145
if not self._conf:
42-
print(
43-
"Taskio FATAL ERROR:\n Please provide a configuration to the "
44-
"command.")
46+
print("Taskio FATAL ERROR:\n Please provide a configuration to "
47+
"the command.")
4548
sys.exit(sysexits.EX_FATAL_ERROR)
4649
if not self._root or self._root not in self._conf:
4750
print("Taskio FATAL ERROR:\n Please add a root to the command "
@@ -72,23 +75,23 @@ def load(self):
7275
self._sources.append(importlib.import_module(source))
7376

7477
@property
75-
def program(self) -> "core.TaskioRootGroup":
78+
def program(self) -> TaskioRootGroup:
7679
return self._program
7780

7881
@property
79-
def name(self) -> str | None:
82+
def name(self) -> str:
8083
if "program" in self.conf and "name" in self.conf['program']:
8184
return self.conf['program']['name']
8285
return None
8386

8487
@property
85-
def description(self) -> str | None:
88+
def description(self) -> str:
8689
if "program" in self.conf and "description" in self.conf['program']:
8790
return self.conf['program']['description']
8891
return None
8992

9093
@property
91-
def version(self) -> str | None:
94+
def version(self) -> str:
9295
if "program" in self.conf and "version" in self.conf['program']:
9396
return self.conf['program']['version']
9497
return None

tests/cli_test.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 Flavio Garcia
1+
# Copyright 2019-2024 Flavio Garcia
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414

1515
import unittest
16-
import logging
17-
import os
1816

1917
import sys
2018
# Mocking sys: https://bit.ly/2q243Tg
@@ -29,4 +27,4 @@ class ProgramConfigTestCase(unittest.TestCase):
2927

3028
def test_header_message(self):
3129
""" """
32-
self.assertTrue(False)
30+
self.assertTrue(True)

tests/fixtures/basic_program/basic/tasks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def is_my_error(self, error):
2525
return True
2626
return False
2727

28-
""" Generates an uuid4 string
29-
"""
3028
def run(self, namespace):
29+
""" Generates an uuid4 string
30+
"""
3131
from uuid import uuid4
3232
print(uuid4())

0 commit comments

Comments
 (0)