File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -113,16 +113,14 @@ class EncodedId(str):
113
113
https://docs.gitlab.com/ee/api/index.html#path-parameters
114
114
"""
115
115
116
- # mypy complains if return type other than the class type. So we ignore issue.
117
- def __new__ ( # type: ignore
118
- cls , value : Union [str , int , "EncodedId" ]
119
- ) -> Union [int , "EncodedId" ]:
120
- if isinstance (value , (int , EncodedId )):
116
+ def __new__ (cls , value : Union [str , int , "EncodedId" ]) -> "EncodedId" :
117
+ if isinstance (value , EncodedId ):
121
118
return value
122
119
123
- if not isinstance (value , str ):
120
+ if not isinstance (value , ( int , str ) ):
124
121
raise TypeError (f"Unsupported type received: { type (value )} " )
125
- value = urllib .parse .quote (value , safe = "" )
122
+ if isinstance (value , str ):
123
+ value = urllib .parse .quote (value , safe = "" )
126
124
return super ().__new__ (cls , value )
127
125
128
126
Original file line number Diff line number Diff line change @@ -48,16 +48,18 @@ def test_init_str(self):
48
48
assert "Hello" == obj
49
49
assert "Hello" == str (obj )
50
50
assert "Hello" == f"{ obj } "
51
+ assert isinstance (obj , utils .EncodedId )
51
52
52
53
obj = utils .EncodedId ("this/is a/path" )
53
54
assert "this%2Fis%20a%2Fpath" == str (obj )
54
55
assert "this%2Fis%20a%2Fpath" == f"{ obj } "
56
+ assert isinstance (obj , utils .EncodedId )
55
57
56
58
def test_init_int (self ):
57
59
obj = utils .EncodedId (23 )
58
- assert 23 == obj
59
- assert "23" == str (obj )
60
+ assert "23" == obj
60
61
assert "23" == f"{ obj } "
62
+ assert isinstance (obj , utils .EncodedId )
61
63
62
64
def test_init_invalid_type_raises (self ):
63
65
with pytest .raises (TypeError ):
You can’t perform that action at this time.
0 commit comments