19
19
from . import normalizers
20
20
from . import uri
21
21
from . import uri_reference
22
+ from ._typing_compat import Self as _Self
22
23
23
24
# Modified from urllib.parse in typeshed.
24
25
_QueryType = t .Union [
@@ -87,7 +88,7 @@ def __repr__(self):
87
88
return formatstr .format (b = self )
88
89
89
90
@classmethod
90
- def from_uri (cls , reference : t .Union ["uri.URIReference" , str ]):
91
+ def from_uri (cls , reference : t .Union ["uri.URIReference" , str ]) -> _Self :
91
92
"""Initialize the URI builder from another URI.
92
93
93
94
Takes the given URI reference and creates a new URI builder instance
@@ -106,7 +107,7 @@ def from_uri(cls, reference: t.Union["uri.URIReference", str]):
106
107
fragment = reference .fragment ,
107
108
)
108
109
109
- def add_scheme (self , scheme : str ):
110
+ def add_scheme (self , scheme : str ) -> "URIBuilder" :
110
111
"""Add a scheme to our builder object.
111
112
112
113
After normalizing, this will generate a new URIBuilder instance with
@@ -130,7 +131,11 @@ def add_scheme(self, scheme: str):
130
131
fragment = self .fragment ,
131
132
)
132
133
133
- def add_credentials (self , username : str , password : t .Optional [str ]):
134
+ def add_credentials (
135
+ self ,
136
+ username : str ,
137
+ password : t .Optional [str ],
138
+ ) -> "URIBuilder" :
134
139
"""Add credentials as the userinfo portion of the URI.
135
140
136
141
.. code-block:: python
@@ -163,7 +168,7 @@ def add_credentials(self, username: str, password: t.Optional[str]):
163
168
fragment = self .fragment ,
164
169
)
165
170
166
- def add_host (self , host : str ):
171
+ def add_host (self , host : str ) -> "URIBuilder" :
167
172
"""Add hostname to the URI.
168
173
169
174
.. code-block:: python
@@ -183,7 +188,7 @@ def add_host(self, host: str):
183
188
fragment = self .fragment ,
184
189
)
185
190
186
- def add_port (self , port : t .Union [str , int ]):
191
+ def add_port (self , port : t .Union [str , int ]) -> "URIBuilder" :
187
192
"""Add port to the URI.
188
193
189
194
.. code-block:: python
@@ -222,7 +227,7 @@ def add_port(self, port: t.Union[str, int]):
222
227
fragment = self .fragment ,
223
228
)
224
229
225
- def add_path (self , path : str ):
230
+ def add_path (self , path : str ) -> "URIBuilder" :
226
231
"""Add a path to the URI.
227
232
228
233
.. code-block:: python
@@ -249,7 +254,7 @@ def add_path(self, path: str):
249
254
fragment = self .fragment ,
250
255
)
251
256
252
- def extend_path (self , path : str ):
257
+ def extend_path (self , path : str ) -> "URIBuilder" :
253
258
"""Extend the existing path value with the provided value.
254
259
255
260
.. versionadded:: 1.5.0
@@ -278,7 +283,7 @@ def extend_path(self, path: str):
278
283
279
284
return self .add_path (path )
280
285
281
- def add_query_from (self , query_items : _QueryType ):
286
+ def add_query_from (self , query_items : _QueryType ) -> "URIBuilder" :
282
287
"""Generate and add a query a dictionary or list of tuples.
283
288
284
289
.. code-block:: python
@@ -304,7 +309,7 @@ def add_query_from(self, query_items: _QueryType):
304
309
fragment = self .fragment ,
305
310
)
306
311
307
- def extend_query_with (self , query_items : _QueryType ):
312
+ def extend_query_with (self , query_items : _QueryType ) -> "URIBuilder" :
308
313
"""Extend the existing query string with the new query items.
309
314
310
315
.. versionadded:: 1.5.0
@@ -325,7 +330,7 @@ def extend_query_with(self, query_items: _QueryType):
325
330
326
331
return self .add_query_from (original_query_items + query_items )
327
332
328
- def add_query (self , query : str ):
333
+ def add_query (self , query : str ) -> "URIBuilder" :
329
334
"""Add a pre-formated query string to the URI.
330
335
331
336
.. code-block:: python
@@ -345,7 +350,7 @@ def add_query(self, query: str):
345
350
fragment = self .fragment ,
346
351
)
347
352
348
- def add_fragment (self , fragment : str ):
353
+ def add_fragment (self , fragment : str ) -> "URIBuilder" :
349
354
"""Add a fragment to the URI.
350
355
351
356
.. code-block:: python
@@ -390,7 +395,7 @@ def finalize(self) -> "uri.URIReference":
390
395
self .fragment ,
391
396
)
392
397
393
- def geturl (self ):
398
+ def geturl (self ) -> str :
394
399
"""Generate the URL from this builder.
395
400
396
401
.. versionadded:: 1.5.0
0 commit comments