diff options
author | John L. Villalovos <john@sodarock.com> | 2021-03-07 11:31:23 -0800 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2021-03-10 08:37:07 -0800 |
commit | 147f05d43d302d9a04bc87d957c79ce9e54cdaed (patch) | |
tree | bb639917a30dbb3de31bf6e47ea022794626bc1c /gitlab/v4/cli.py | |
parent | 6fde2437e82aeb8af903f81e351790b4695074a1 (diff) | |
download | gitlab-147f05d43d302d9a04bc87d957c79ce9e54cdaed.tar.gz |
chore: add _create_attrs & _update_attrs to RESTManager
Add the attributes: _create_attrs and _update_attrs to the RESTManager
class. This is so that we stop using getattr() if we don't need to.
This also helps with type-hints being available for these attributes.
Diffstat (limited to 'gitlab/v4/cli.py')
-rw-r--r-- | gitlab/v4/cli.py | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index c01f06b..df645bf 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -177,42 +177,31 @@ def _populate_sub_parser_by_class(cls, sub_parser): ] if action_name == "create": - if hasattr(mgr_cls, "_create_attrs"): - [ - sub_parser_action.add_argument( - "--%s" % x.replace("_", "-"), required=True - ) - for x in mgr_cls._create_attrs[0] - ] - - [ - sub_parser_action.add_argument( - "--%s" % x.replace("_", "-"), required=False - ) - for x in mgr_cls._create_attrs[1] - ] + for x in mgr_cls._create_attrs[0]: + sub_parser_action.add_argument( + "--%s" % x.replace("_", "-"), required=True + ) + for x in mgr_cls._create_attrs[1]: + sub_parser_action.add_argument( + "--%s" % x.replace("_", "-"), required=False + ) if action_name == "update": if cls._id_attr is not None: id_attr = cls._id_attr.replace("_", "-") sub_parser_action.add_argument("--%s" % id_attr, required=True) - if hasattr(mgr_cls, "_update_attrs"): - [ + for x in mgr_cls._update_attrs[0]: + if x != cls._id_attr: sub_parser_action.add_argument( "--%s" % x.replace("_", "-"), required=True ) - for x in mgr_cls._update_attrs[0] - if x != cls._id_attr - ] - [ + for x in mgr_cls._update_attrs[1]: + if x != cls._id_attr: sub_parser_action.add_argument( "--%s" % x.replace("_", "-"), required=False ) - for x in mgr_cls._update_attrs[1] - if x != cls._id_attr - ] if cls.__name__ in cli.custom_actions: name = cls.__name__ |