summaryrefslogtreecommitdiff
path: root/gitlab/utils.py
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-06-01 01:19:19 +0200
committerGitHub <noreply@github.com>2022-06-01 01:19:19 +0200
commitdea9435f21ededac998ba878a4fd2def698a3066 (patch)
tree0e17ac46ad58b18f1fdd7c15540898bade5e6f30 /gitlab/utils.py
parent3fa330cc341bbedb163ba757c7f6578d735c6efb (diff)
parenta1a246fbfcf530732249a263ee42757a862181aa (diff)
downloadgitlab-dea9435f21ededac998ba878a4fd2def698a3066.tar.gz
Merge pull request #2040 from python-gitlab/jlvillal/type_alias
chore: have `EncodedId` creation always return `EncodedId`
Diffstat (limited to 'gitlab/utils.py')
-rw-r--r--gitlab/utils.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py
index e8eb941..7c94569 100644
--- a/gitlab/utils.py
+++ b/gitlab/utils.py
@@ -113,16 +113,14 @@ class EncodedId(str):
https://docs.gitlab.com/ee/api/index.html#path-parameters
"""
- # mypy complains if return type other than the class type. So we ignore issue.
- def __new__( # type: ignore
- cls, value: Union[str, int, "EncodedId"]
- ) -> Union[int, "EncodedId"]:
- if isinstance(value, (int, EncodedId)):
+ def __new__(cls, value: Union[str, int, "EncodedId"]) -> "EncodedId":
+ if isinstance(value, EncodedId):
return value
- if not isinstance(value, str):
+ if not isinstance(value, (int, str)):
raise TypeError(f"Unsupported type received: {type(value)}")
- value = urllib.parse.quote(value, safe="")
+ if isinstance(value, str):
+ value = urllib.parse.quote(value, safe="")
return super().__new__(cls, value)