10000 chore: create return type-hints for `get_id()` & `encoded_id` · python-gitlab/python-gitlab@0c3a1d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c3a1d1

Browse files
chore: create return type-hints for get_id() & encoded_id
Create return type-hints for `RESTObject.get_id()` and `RESTObject.encoded_id`. Previously was saying they return Any. Be more precise in saying they can return either: None, str, or int.
1 parent a1dbe86 commit 0c3a1d1

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

gitlab/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import pprint
2020
import textwrap
2121
from types import ModuleType
22-
from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type
22+
from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type, Union
2323

2424
import gitlab
2525
from gitlab import types as g_types
@@ -211,14 +211,14 @@ def _update_attrs(self, new_attrs: Dict[str, Any]) -> None:
211211
self.__dict__["_updated_attrs"] = {}
212212
self.__dict__["_attrs"] = new_attrs
213213

214-
def get_id(self) -> Any:
214+
def get_id(self) -> Optional[Union[int, str]]:
215215
"""Returns the id of the resource."""
216216
if self._id_attr is None or not hasattr(self, self._id_attr):
217217
return None
218218
return getattr(self, self._id_attr)
219219

220220
@property
221-
def encoded_id(self) -> Any:
221+
def encoded_id(self) -> Optional[Union[int, str]]:
222222
"""Ensure that the ID is url-encoded so that it can be safely used in a URL
223223
path"""
224224
obj_id = self.get_id()

gitlab/mixins.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def delete(self, **kwargs: Any) -> None:
576576
"""
577577
if TYPE_CHECKING:
578578
assert isinstance(self.manager, DeleteMixin)
579+
assert self.encoded_id is not None
579580
self.manager.delete(self.encoded_id, **kwargs)
580581

581582

gitlab/v4/objects/files.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def delete( # type: ignore
7777
GitlabDeleteError: If the server cannot perform the request
7878
"""
7979
file_path = self.encoded_id
80+
if TYPE_CHECKING:
81+
assert isinstance(file_path, str)
8082
self.manager.delete(file_path, branch, commit_message, **kwargs)
8183

8284

0 commit comments

Comments
 (0)
0