Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: haveEncodedId creation always returnEncodedId#2040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intomainfromjlvillal/type_alias
May 31, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletionsgitlab/utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)


Expand Down
6 changes: 4 additions & 2 deletionstests/unit/test_utils.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,16 +48,18 @@ def test_init_str(self):
assert "Hello" == obj
assert "Hello" == str(obj)
assert "Hello" == f"{obj}"
assert isinstance(obj, utils.EncodedId)

obj = utils.EncodedId("this/is a/path")
assert "this%2Fis%20a%2Fpath" == str(obj)
assert "this%2Fis%20a%2Fpath" == f"{obj}"
assert isinstance(obj, utils.EncodedId)

def test_init_int(self):
obj = utils.EncodedId(23)
assert 23 == obj
assert "23" == str(obj)
assert "23" == obj
assert "23" == f"{obj}"
assert isinstance(obj, utils.EncodedId)

def test_init_invalid_type_raises(self):
with pytest.raises(TypeError):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp