diff options
author | Nejc Habjan <hab.nejc@gmail.com> | 2022-01-15 01:07:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-15 01:07:41 +0100 |
commit | 1ac982ae30781830c2a19a83a014e04a4b6bae41 (patch) | |
tree | cef48e066620e4802711ad38f2b7381d3825c93e | |
parent | a1dbe86c20b205ce135a7592d5c551e67adfb929 (diff) | |
parent | 0c3a1d163895f660340a6c2b2f196ad996542518 (diff) | |
download | gitlab-1ac982ae30781830c2a19a83a014e04a4b6bae41.tar.gz |
Merge pull request #1841 from python-gitlab/jlvillal/get_id
chore: create return type-hints for `get_id()` & `encoded_id`
-rw-r--r-- | gitlab/base.py | 6 | ||||
-rw-r--r-- | gitlab/mixins.py | 1 | ||||
-rw-r--r-- | gitlab/v4/objects/files.py | 2 |
3 files changed, 6 insertions, 3 deletions
diff --git a/gitlab/base.py b/gitlab/base.py index 0706ffb..dc7a004 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -19,7 +19,7 @@ import importlib import pprint import textwrap from types import ModuleType -from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type +from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type, Union import gitlab from gitlab import types as g_types @@ -211,14 +211,14 @@ class RESTObject(object): self.__dict__["_updated_attrs"] = {} self.__dict__["_attrs"] = new_attrs - def get_id(self) -> Any: + def get_id(self) -> Optional[Union[int, str]]: """Returns the id of the resource.""" if self._id_attr is None or not hasattr(self, self._id_attr): return None return getattr(self, self._id_attr) @property - def encoded_id(self) -> Any: + def encoded_id(self) -> Optional[Union[int, str]]: """Ensure that the ID is url-encoded so that it can be safely used in a URL path""" obj_id = self.get_id() diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 0d22b78..d66b2eb 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -576,6 +576,7 @@ class ObjectDeleteMixin(_RestObjectBase): """ if TYPE_CHECKING: assert isinstance(self.manager, DeleteMixin) + assert self.encoded_id is not None self.manager.delete(self.encoded_id, **kwargs) diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index 0a56fef..4ff5b3a 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -77,6 +77,8 @@ class ProjectFile(SaveMixin, ObjectDeleteMixin, RESTObject): GitlabDeleteError: If the server cannot perform the request """ file_path = self.encoded_id + if TYPE_CHECKING: + assert isinstance(file_path, str) self.manager.delete(file_path, branch, commit_message, **kwargs) |