Skip to content

Commit

Permalink
Fix port not being marked as int in several places.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Sachaa-Thanasius committed Jun 17, 2024
1 parent 9e812f3 commit 9862d65
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/rfc3986/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


class _AuthorityInfo(t.TypedDict):
"""A typed dict for the authority info triple: userinfo, host, and port."""

userinfo: t.Optional[str]
host: t.Optional[str]
port: t.Optional[str]
Expand Down
4 changes: 2 additions & 2 deletions src/rfc3986/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __new__(
query: t.Optional[str],
fragment: t.Optional[str],
encoding: str = "utf-8",
):
) -> _Self:
"""Create a new IRIReference."""
ref = super().__new__(
cls,
Expand All @@ -65,7 +65,7 @@ def __new__(

__hash__ = tuple.__hash__

def __eq__(self, other: object):
def __eq__(self, other: object) -> bool:
"""Compare this reference to another."""
other_ref = other
if isinstance(other, tuple):
Expand Down
18 changes: 9 additions & 9 deletions src/rfc3986/parseresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ParseResult(
scheme: t.Optional[str]
userinfo: t.Optional[str]
host: t.Optional[str]
port: t.Optional[str]
port: t.Optional[int]
path: t.Optional[str]
query: t.Optional[str]
fragment: t.Optional[str]
Expand All @@ -103,13 +103,13 @@ def __new__(
scheme: t.Optional[str],
userinfo: t.Optional[str],
host: t.Optional[str],
port: t.Optional[str],
port: t.Optional[int],
path: t.Optional[str],
query: t.Optional[str],
fragment: t.Optional[str],
uri_ref: "uri.URIReference",
encoding: str = "utf-8",
):
) -> _Self:
"""Create a new ParseResult."""
parse_result = super().__new__(
cls,
Expand Down Expand Up @@ -201,7 +201,7 @@ def from_string(
)

@property
def authority(self):
def authority(self) -> t.Optional[str]:
"""Return the normalized authority."""
return self.reference.authority

Expand All @@ -214,7 +214,7 @@ def copy_with(
path: t.Optional[str] = misc.UseExisting,
query: t.Optional[str] = misc.UseExisting,
fragment: t.Optional[str] = misc.UseExisting,
):
) -> "ParseResult":
"""Create a copy of this instance replacing with specified parts."""
attributes = zip(
PARSED_COMPONENTS,
Expand Down Expand Up @@ -273,7 +273,7 @@ class ParseResultBytes(
scheme: t.Optional[bytes]
userinfo: t.Optional[bytes]
host: t.Optional[bytes]
port: t.Optional[bytes]
port: t.Optional[int]
path: t.Optional[bytes]
query: t.Optional[bytes]
fragment: t.Optional[bytes]
Expand All @@ -286,14 +286,14 @@ def __new__(
scheme: t.Optional[bytes],
userinfo: t.Optional[bytes],
host: t.Optional[bytes],
port: t.Optional[bytes],
port: t.Optional[int],
path: t.Optional[bytes],
query: t.Optional[bytes],
fragment: t.Optional[bytes],
uri_ref: "uri.URIReference",
encoding: str = "utf-8",
lazy_normalize: bool = True,
):
) -> _Self:
"""Create a new ParseResultBytes instance."""
parse_result = super().__new__(
cls,
Expand Down Expand Up @@ -322,7 +322,7 @@ def from_parts(
fragment: t.Optional[str] = None,
encoding: str = "utf-8",
lazy_normalize: bool = True,
):
) -> _Self:
"""Create a ParseResult instance from its parts."""
authority = ""
if userinfo is not None:
Expand Down
4 changes: 2 additions & 2 deletions src/rfc3986/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __new__(
query: t.Optional[str],
fragment: t.Optional[str],
encoding: str = "utf-8",
):
) -> _Self:
"""Create a new URIReference."""
ref = super().__new__(
cls,
Expand All @@ -105,7 +105,7 @@ def __new__(

__hash__ = tuple.__hash__

def __eq__(self, other: object):
def __eq__(self, other: object) -> bool:
"""Compare this reference to another."""
other_ref = other
if isinstance(other, tuple):
Expand Down

0 comments on commit 9862d65

Please sign in to comment.