Skip to content

Commit 8933113

Browse files
chore: make ListMixin._list_filters always present
Always create ListMixin._list_filters 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 8933113

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

gitlab/mixins.py

Lines changed: 2 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,
@@ -186,6 +187,7 @@ def refresh(self, **kwargs: Any) -> None:
186187
class ListMixin(_RestManagerBase):
187188
_computed_path: Optional[str]
188189
_from_parent_attrs: Dict[str, Any]
190+
_list_filters: Tuple[str, ...] = ()
189191
_obj_cls: Optional[Type[base.RESTObject]]
190192
_parent: Optional[base.RESTObject]
191193
_parent_attrs: Dict[str, Any]

gitlab/v4/cli.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,10 @@ def _populate_sub_parser_by_class(cls, sub_parser):
145145
)
146146

147147
if action_name == "list":
148-
if hasattr(mgr_cls, "_list_filters"):
149-
[
150-
sub_parser_action.add_argument(
151-
"--%s" % x.replace("_", "-"), required=False
152-
)
153-
for x in mgr_cls._list_filters
154-
]
148+
for x in mgr_cls._list_filters:
149+
sub_parser_action.add_argument(
150+
"--%s" % x.replace("_", "-"), required=False
151+
)
155152

156153
sub_parser_action.add_argument("--page", required=False)
157154
sub_parser_action.add_argument("--per-page", required=False)

0 commit comments

Comments
 (0)