Skip to content

Commit 3969c1d

Browse files
Finish annotating return types in builder.py.
1 parent 0179352 commit 3969c1d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/rfc3986/builder.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from . import normalizers
2020
from . import uri
2121
from . import uri_reference
22+
from ._typing_compat import Self as _Self
2223

2324
# Modified from urllib.parse in typeshed.
2425
_QueryType = t.Union[
@@ -87,7 +88,7 @@ def __repr__(self):
8788
return formatstr.format(b=self)
8889

8990
@classmethod
90-
def from_uri(cls, reference: t.Union["uri.URIReference", str]):
91+
def from_uri(cls, reference: t.Union["uri.URIReference", str]) -> _Self:
9192
"""Initialize the URI builder from another URI.
9293
9394
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]):
106107
fragment=reference.fragment,
107108
)
108109

109-
def add_scheme(self, scheme: str):
110+
def add_scheme(self, scheme: str) -> "URIBuilder":
110111
"""Add a scheme to our builder object.
111112
112113
After normalizing, this will generate a new URIBuilder instance with
@@ -130,7 +131,11 @@ def add_scheme(self, scheme: str):
130131
fragment=self.fragment,
131132
)
132133

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":
134139
"""Add credentials as the userinfo portion of the URI.
135140
136141
.. code-block:: python
@@ -163,7 +168,7 @@ def add_credentials(self, username: str, password: t.Optional[str]):
163168
fragment=self.fragment,
164169
)
165170

166-
def add_host(self, host: str):
171+
def add_host(self, host: str) -> "URIBuilder":
167172
"""Add hostname to the URI.
168173
169174
.. code-block:: python
@@ -183,7 +188,7 @@ def add_host(self, host: str):
183188
fragment=self.fragment,
184189
)
185190

186-
def add_port(self, port: t.Union[str, int]):
191+
def add_port(self, port: t.Union[str, int]) -> "URIBuilder":
187192
"""Add port to the URI.
188193
189194
.. code-block:: python
@@ -222,7 +227,7 @@ def add_port(self, port: t.Union[str, int]):
222227
fragment=self.fragment,
223228
)
224229

225-
def add_path(self, path: str):
230+
def add_path(self, path: str) -> "URIBuilder":
226231
"""Add a path to the URI.
227232
228233
.. code-block:: python
@@ -249,7 +254,7 @@ def add_path(self, path: str):
249254
fragment=self.fragment,
250255
)
251256

252-
def extend_path(self, path: str):
257+
def extend_path(self, path: str) -> "URIBuilder":
253258
"""Extend the existing path value with the provided value.
254259
255260
.. versionadded:: 1.5.0
@@ -278,7 +283,7 @@ def extend_path(self, path: str):
278283

279284
return self.add_path(path)
280285

281-
def add_query_from(self, query_items: _QueryType):
286+
def add_query_from(self, query_items: _QueryType) -> "URIBuilder":
282287
"""Generate and add a query a dictionary or list of tuples.
283288
284289
.. code-block:: python
@@ -304,7 +309,7 @@ def add_query_from(self, query_items: _QueryType):
304309
fragment=self.fragment,
305310
)
306311

307-
def extend_query_with(self, query_items: _QueryType):
312+
def extend_query_with(self, query_items: _QueryType) -> "URIBuilder":
308313
"""Extend the existing query string with the new query items.
309314
310315
.. versionadded:: 1.5.0
@@ -325,7 +330,7 @@ def extend_query_with(self, query_items: _QueryType):
325330

326331
return self.add_query_from(original_query_items + query_items)
327332

328-
def add_query(self, query: str):
333+
def add_query(self, query: str) -> "URIBuilder":
329334
"""Add a pre-formated query string to the URI.
330335
331336
.. code-block:: python
@@ -345,7 +350,7 @@ def add_query(self, query: str):
345350
fragment=self.fragment,
346351
)
347352

348-
def add_fragment(self, fragment: str):
353+
def add_fragment(self, fragment: str) -> "URIBuilder":
349354
"""Add a fragment to the URI.
350355
351356
.. code-block:: python
@@ -390,7 +395,7 @@ def finalize(self) -> "uri.URIReference":
390395
self.fragment,
391396
)
392397

393-
def geturl(self):
398+
def geturl(self) -> str:
394399
"""Generate the URL from this builder.
395400
396401
.. versionadded:: 1.5.0

0 commit comments

Comments
 (0)