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):
113113 https://docs.gitlab.com/ee/api/index.html#path-parameters
114114 """
115115
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 ):
121118 return value
122119
123- if not isinstance (value , str ):
120+ if not isinstance (value , ( int , str ) ):
124121 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 = "" )
126124 return super ().__new__ (cls , value )
127125
128126
Original file line number Diff line number Diff line change @@ -48,16 +48,18 @@ def test_init_str(self):
4848 assert "Hello" == obj
4949 assert "Hello" == str (obj )
5050 assert "Hello" == f"{ obj } "
51+ assert isinstance (obj , utils .EncodedId )
5152
5253 obj = utils .EncodedId ("this/is a/path" )
5354 assert "this%2Fis%20a%2Fpath" == str (obj )
5455 assert "this%2Fis%20a%2Fpath" == f"{ obj } "
56+ assert isinstance (obj , utils .EncodedId )
5557
5658 def test_init_int (self ):
5759 obj = utils .EncodedId (23 )
58- assert 23 == obj
59- assert "23" == str (obj )
60+ assert "23" == obj
6061 assert "23" == f"{ obj } "
62+ assert isinstance (obj , utils .EncodedId )
6163
6264 def test_init_invalid_type_raises (self ):
6365 with pytest .raises (TypeError ):
You can’t perform that action at this time.
0 commit comments