summaryrefslogtreecommitdiff
path: root/gitlab/cli.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2021-02-26 17:35:02 -0800
committerJohn L. Villalovos <john@sodarock.com>2021-02-28 08:48:31 -0800
commit907634fe4d0d30706656b8bc56260b5532613e62 (patch)
tree364677392e08928753133128174d049ff2c8c41d /gitlab/cli.py
parentd8b8a0a010b41465586dccf198582ae127a31530 (diff)
downloadgitlab-907634fe4d0d30706656b8bc56260b5532613e62.tar.gz
chore: disallow incomplete type defs
Don't allow a partially annotated function definition. Either none of the function is annotated or all of it must be. Update code to ensure no-more partially annotated functions. Update gitlab/cli.py with better type-hints. Changed Tuple[Any, ...] to Tuple[str, ...]
Diffstat (limited to 'gitlab/cli.py')
-rw-r--r--gitlab/cli.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py
index 1e98a38..bd2c13d 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -21,7 +21,7 @@ import argparse
import functools
import re
import sys
-from typing import Any, Callable, Dict, Tuple
+from typing import Any, Callable, Dict, Optional, Tuple, Union
import gitlab.config
@@ -32,21 +32,24 @@ camel_re = re.compile("(.)([A-Z])")
# action: (mandatory_args, optional_args, in_obj),
# },
# }
-custom_actions: Dict[str, Dict[str, Tuple[Tuple[Any, ...], Tuple[Any, ...], bool]]] = {}
+custom_actions: Dict[str, Dict[str, Tuple[Tuple[str, ...], Tuple[str, ...], bool]]] = {}
def register_custom_action(
- cls_names, mandatory: Tuple[Any, ...] = tuple(), optional: Tuple[Any, ...] = tuple()
+ cls_names: Union[str, Tuple[str, ...]],
+ mandatory: Tuple[str, ...] = tuple(),
+ optional: Tuple[str, ...] = tuple(),
) -> Callable:
- def wrap(f) -> Callable:
+ def wrap(f: Callable) -> Callable:
@functools.wraps(f)
def wrapped_f(*args, **kwargs):
return f(*args, **kwargs)
# in_obj defines whether the method belongs to the obj or the manager
in_obj = True
- classes = cls_names
- if type(cls_names) != tuple:
+ if isinstance(cls_names, tuple):
+ classes = cls_names
+ else:
classes = (cls_names,)
for cls_name in classes:
@@ -65,7 +68,7 @@ def register_custom_action(
return wrap
-def die(msg: str, e=None) -> None:
+def die(msg: str, e: Optional[Exception] = None) -> None:
if e:
msg = "%s (%s)" % (msg, e)
sys.stderr.write(msg + "\n")
@@ -76,7 +79,7 @@ def what_to_cls(what: str) -> str:
return "".join([s.capitalize() for s in what.split("-")])
-def cls_to_what(cls) -> str:
+def cls_to_what(cls: Any) -> str:
return camel_re.sub(r"\1-\2", cls.__name__).lower()