From 147f05d43d302d9a04bc87d957c79ce9e54cdaed Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Sun, 7 Mar 2021 11:31:23 -0800 Subject: 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. --- gitlab/v4/cli.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'gitlab/v4/cli.py') 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__ -- cgit v1.2.1