summaryrefslogtreecommitdiff
path: root/gitlab/v4/cli.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-08-01 00:29:18 -0700
committerJohn L. Villalovos <john@sodarock.com>2022-08-01 00:29:18 -0700
commit24d17b43da16dd11ab37b2cee561d9392c90f32e (patch)
tree2adacb59887c121231dd98cf04523c57674ba9c5 /gitlab/v4/cli.py
parent54dd4c3f857f82aa8781b0daf22fa2dd3c60c2c4 (diff)
downloadgitlab-24d17b43da16dd11ab37b2cee561d9392c90f32e.tar.gz
chore: enable mypy check `disallow_any_generics`
Diffstat (limited to 'gitlab/v4/cli.py')
-rw-r--r--gitlab/v4/cli.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py
index 48369f6..fbc11c2 100644
--- a/gitlab/v4/cli.py
+++ b/gitlab/v4/cli.py
@@ -210,8 +210,16 @@ class GitlabCLI:
return result
+# https://github.com/python/typeshed/issues/7539#issuecomment-1076581049
+if TYPE_CHECKING:
+ _SubparserType = argparse._SubParsersAction[argparse.ArgumentParser]
+else:
+ _SubparserType = Any
+
+
def _populate_sub_parser_by_class(
- cls: Type[gitlab.base.RESTObject], sub_parser: argparse._SubParsersAction
+ cls: Type[gitlab.base.RESTObject],
+ sub_parser: _SubparserType,
) -> None:
mgr_cls_name = f"{cls.__name__}Manager"
mgr_cls = getattr(gitlab.v4.objects, mgr_cls_name)
@@ -301,9 +309,11 @@ def _populate_sub_parser_by_class(
for action_name in cli.custom_actions[name]:
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
- sub_parser_action = action_parsers.get(action_name)
- if sub_parser_action is None:
+ action_parser = action_parsers.get(action_name)
+ if action_parser is None:
sub_parser_action = sub_parser.add_parser(action_name)
+ else:
+ sub_parser_action = action_parser
# Get the attributes for URL/path construction
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
@@ -335,9 +345,11 @@ def _populate_sub_parser_by_class(
for action_name in cli.custom_actions[name]:
# NOTE(jlvillal): If we put a function for the `default` value of
# the `get` it will always get called, which will break things.
- sub_parser_action = action_parsers.get(action_name)
- if sub_parser_action is None:
+ action_parser = action_parsers.get(action_name)
+ if action_parser is None:
sub_parser_action = sub_parser.add_parser(action_name)
+ else:
+ sub_parser_action = action_parser
if mgr_cls._from_parent_attrs:
for x in mgr_cls._from_parent_attrs:
sub_parser_action.add_argument(