summaryrefslogtreecommitdiff
path: root/gitlab/base.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2021-06-12 15:05:36 -0700
committerJohn L. Villalovos <john@sodarock.com>2021-09-07 08:19:39 -0700
commitc9b5d3bac8f7c1f779dd57653f718dd0fac4db4b (patch)
tree925700991c94a5a71797d6992b97c5b90ed74089 /gitlab/base.py
parentb8a47bae3342400a411fb9bf4bef3c15ba91c98e (diff)
downloadgitlab-c9b5d3bac8f7c1f779dd57653f718dd0fac4db4b.tar.gz
chore: improve type-hinting for managers
The 'managers' are dynamically created. This unfortunately means that we don't have any type-hints for them and so editors which understand type-hints won't know that they are valid attributes. * Add the type-hints for the managers we define. * Add a unit test that makes sure that the type-hints and the '_managers' attribute are kept in sync with each other. * Add unit test that makes sure specified managers in '_managers' have a name ending in 'Managers' to keep with current convention. * Make RESTObject._managers always present with a default value of None. * Fix a type-issue revealed now that mypy knows what the type is
Diffstat (limited to 'gitlab/base.py')
-rw-r--r--gitlab/base.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/gitlab/base.py b/gitlab/base.py
index bea1901..361832e 100644
--- a/gitlab/base.py
+++ b/gitlab/base.py
@@ -49,6 +49,7 @@ class RESTObject(object):
_parent_attrs: Dict[str, Any]
_short_print_attr: Optional[str] = None
_updated_attrs: Dict[str, Any]
+ _managers: Optional[Iterable[Tuple[str, str]]] = None
manager: "RESTManager"
def __init__(self, manager: "RESTManager", attrs: Dict[str, Any]) -> None:
@@ -150,13 +151,13 @@ class RESTObject(object):
return hash(self.get_id())
def _create_managers(self) -> None:
- managers = getattr(self, "_managers", None)
- if managers is None:
+ if self._managers is None:
return
for attr, cls_name in self._managers:
cls = getattr(self._module, cls_name)
manager = cls(self.manager.gitlab, parent=self)
+ # Since we have our own __setattr__ method, we can't use setattr()
self.__dict__[attr] = manager
def _update_attrs(self, new_attrs: Dict[str, Any]) -> None: