summaryrefslogtreecommitdiff
path: root/gitlab/base.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2021-11-24 17:43:46 -0800
committerJohn L. Villalovos <john@sodarock.com>2021-11-24 20:41:36 -0800
commit308210b3dee15c844cd5db4ddd8c7404bb188990 (patch)
tree4df88a7a967e209afcf2efea9efc5fd8be358128 /gitlab/base.py
parentab82fd84ba3cecf766915112dcb46fdfab383e73 (diff)
downloadgitlab-jlvillal/mypy_strict.tar.gz
WIP: work on enable mypy 'strict' modejlvillal/mypy_strict
Diffstat (limited to 'gitlab/base.py')
-rw-r--r--gitlab/base.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/gitlab/base.py b/gitlab/base.py
index 5e5f57b..8dcae7d 100644
--- a/gitlab/base.py
+++ b/gitlab/base.py
@@ -17,7 +17,17 @@
import importlib
from types import ModuleType
-from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type
+from typing import (
+ Any,
+ Dict,
+ Iterable,
+ NamedTuple,
+ Optional,
+ Tuple,
+ Type,
+ TYPE_CHECKING,
+ Union,
+)
from gitlab import types as g_types
from gitlab.exceptions import GitlabParsingError
@@ -172,15 +182,18 @@ 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)
+ id_val = getattr(self, self._id_attr)
+ if TYPE_CHECKING:
+ assert isinstance(id_val, (int, str))
+ return id_val
@property
def attributes(self) -> Dict[str, Any]:
- d = self.__dict__["_updated_attrs"].copy()
+ d: Dict[str, Any] = self.__dict__["_updated_attrs"].copy()
d.update(self.__dict__["_attrs"])
d.update(self.__dict__["_parent_attrs"])
return d