Skip to content

Commit 3c1a0b3

Browse files
chore: make Get.*Mixin._optional_get_attrs always present
Always create GetMixin/GetWithoutIdMixin._optional_get_attrs attribute with a default value of tuple() This way we don't need to use hasattr() and we will know the type of the attribute.
1 parent cfc42d2 commit 3c1a0b3

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

gitlab/mixins.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Dict,
2323
List,
2424
Optional,
25+
Tuple,
2526
Type,
2627
TYPE_CHECKING,
2728
Union,
@@ -74,6 +75,7 @@ class GetMixin(_RestManagerBase):
7475
_computed_path: Optional[str]
7576
_from_parent_attrs: Dict[str, Any]
7677
_obj_cls: Optional[Type[base.RESTObject]]
78+
_optional_get_attrs: Tuple[str, ...] = ()
7779
_parent: Optional[base.RESTObject]
7880
_parent_attrs: Dict[str, Any]
7981
_path: Optional[str]
@@ -118,6 +120,7 @@ class GetWithoutIdMixin(_RestManagerBase):
118120
_computed_path: Optional[str]
119121
_from_parent_attrs: Dict[str, Any]
120122
_obj_cls: Optional[Type[base.RESTObject]]
123+
_optional_get_attrs: Tuple[str, ...] = ()
121124
_parent: Optional[base.RESTObject]
122125
_parent_attrs: Dict[str, Any]
123126
_path: Optional[str]

gitlab/v4/cli.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,10 @@ def _populate_sub_parser_by_class(cls, sub_parser):
168168
id_attr = cls._id_attr.replace("_", "-")
169169
sub_parser_action.add_argument("--%s" % id_attr, required=True)
170170

171-
if hasattr(mgr_cls, "_optional_get_attrs"):
172-
[
173-
sub_parser_action.add_argument(
174-
"--%s" % x.replace("_", "-"), required=False
175-
)
176-
for x in mgr_cls._optional_get_attrs
177-
]
171+
for x in mgr_cls._optional_get_attrs:
172+
sub_parser_action.add_argument(
173+
"--%s" % x.replace("_", "-"), required=False
174+
)
178175

179176
if action_name == "create":
180177
for x in mgr_cls._create_attrs.required:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy