Skip to content

Commit 9862d65

Browse files
Fix port not being marked as int in several places.
- I was confused on what the interface for port was initially, but a close look at how it's tested gave me a better idea. - Also, add a few explicit return annotations.
1 parent 9e812f3 commit 9862d65

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/rfc3986/_mixin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
class _AuthorityInfo(t.TypedDict):
13+
"""A typed dict for the authority info triple: userinfo, host, and port."""
14+
1315
userinfo: t.Optional[str]
1416
host: t.Optional[str]
1517
port: t.Optional[str]

src/rfc3986/iri.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __new__(
5050
query: t.Optional[str],
5151
fragment: t.Optional[str],
5252
encoding: str = "utf-8",
53-
):
53+
) -> _Self:
5454
"""Create a new IRIReference."""
5555
ref = super().__new__(
5656
cls,
@@ -65,7 +65,7 @@ def __new__(
6565

6666
__hash__ = tuple.__hash__
6767

68-
def __eq__(self, other: object):
68+
def __eq__(self, other: object) -> bool:
6969
"""Compare this reference to another."""
7070
other_ref = other
7171
if isinstance(other, tuple):

src/rfc3986/parseresult.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ParseResult(
9191
scheme: t.Optional[str]
9292
userinfo: t.Optional[str]
9393
host: t.Optional[str]
94-
port: t.Optional[str]
94+
port: t.Optional[int]
9595
path: t.Optional[str]
9696
query: t.Optional[str]
9797
fragment: t.Optional[str]
@@ -103,13 +103,13 @@ def __new__(
103103
scheme: t.Optional[str],
104104
userinfo: t.Optional[str],
105105
host: t.Optional[str],
106-
port: t.Optional[str],
106+
port: t.Optional[int],
107107
path: t.Optional[str],
108108
query: t.Optional[str],
109109
fragment: t.Optional[str],
110110
uri_ref: "uri.URIReference",
111111
encoding: str = "utf-8",
112-
):
112+
) -> _Self:
113113
"""Create a new ParseResult."""
114114
parse_result = super().__new__(
115115
cls,
@@ -201,7 +201,7 @@ def from_string(
201201
)
202202

203203
@property
204-
def authority(self):
204+
def authority(self) -> t.Optional[str]:
205205
"""Return the normalized authority."""
206206
return self.reference.authority
207207

@@ -214,7 +214,7 @@ def copy_with(
214214
path: t.Optional[str] = misc.UseExisting,
215215
query: t.Optional[str] = misc.UseExisting,
216216
fragment: t.Optional[str] = misc.UseExisting,
217-
):
217+
) -> "ParseResult":
218218
"""Create a copy of this instance replacing with specified parts."""
219219
attributes = zip(
220220
PARSED_COMPONENTS,
@@ -273,7 +273,7 @@ class ParseResultBytes(
273273
scheme: t.Optional[bytes]
274274
userinfo: t.Optional[bytes]
275275
host: t.Optional[bytes]
276-
port: t.Optional[bytes]
276+
port: t.Optional[int]
277277
path: t.Optional[bytes]
278278
query: t.Optional[bytes]
279279
fragment: t.Optional[bytes]
@@ -286,14 +286,14 @@ def __new__(
286286
scheme: t.Optional[bytes],
287287
userinfo: t.Optional[bytes],
288288
host: t.Optional[bytes],
289-
port: t.Optional[bytes],
289+
port: t.Optional[int],
290290
path: t.Optional[bytes],
291291
query: t.Optional[bytes],
292292
fragment: t.Optional[bytes],
293293
uri_ref: "uri.URIReference",
294294
encoding: str = "utf-8",
295295
lazy_normalize: bool = True,
296-
):
296+
) -> _Self:
297297
"""Create a new ParseResultBytes instance."""
298298
parse_result = super().__new__(
299299
cls,
@@ -322,7 +322,7 @@ def from_parts(
322322
fragment: t.Optional[str] = None,
323323
encoding: str = "utf-8",
324324
lazy_normalize: bool = True,
325-
):
325+
) -> _Self:
326326
"""Create a ParseResult instance from its parts."""
327327
authority = ""
328328
if userinfo is not None:

src/rfc3986/uri.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __new__(
9090
query: t.Optional[str],
9191
fragment: t.Optional[str],
9292
encoding: str = "utf-8",
93-
):
93+
) -> _Self:
9494
"""Create a new URIReference."""
9595
ref = super().__new__(
9696
cls,
@@ -105,7 +105,7 @@ def __new__(
105105

106106
__hash__ = tuple.__hash__
107107

108-
def __eq__(self, other: object):
108+
def __eq__(self, other: object) -> bool:
109109
"""Compare this reference to another."""
110110
other_ref = other
111111
if isinstance(other, tuple):

0 commit comments

Comments
 (0)