Skip to content

Commit

Permalink
Fix: Removing the bytearray hints. Sticking to bytes and str is simpl…
Browse files Browse the repository at this point in the history
…er and close enough to urlllib.parse's interfaces.

- bytearray would end up pervading everything, I think, to the point where it's not worth it. I was hasty in adding those initially.
  • Loading branch information
Sachaa-Thanasius committed Jun 15, 2024
1 parent d99f274 commit f4d150f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
16 changes: 5 additions & 11 deletions src/rfc3986/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def uri_reference(
uri: t.Union[str, bytes, bytearray],
uri: t.Union[str, bytes],
encoding: str = "utf-8",
) -> URIReference:
"""Parse a URI string into a URIReference.
Expand All @@ -42,7 +42,7 @@ def uri_reference(


def iri_reference(
iri: t.Union[str, bytes, bytearray],
iri: t.Union[str, bytes],
encoding: str = "utf-8",
) -> IRIReference:
"""Parse a IRI string into an IRIReference.
Expand All @@ -59,7 +59,7 @@ def iri_reference(


def is_valid_uri(
uri: t.Union[str, bytes, bytearray],
uri: t.Union[str, bytes],
encoding: str = "utf-8",
**kwargs: bool,
) -> bool:
Expand Down Expand Up @@ -87,10 +87,7 @@ def is_valid_uri(
return URIReference.from_string(uri, encoding).is_valid(**kwargs)


def normalize_uri(
uri: t.Union[str, bytes, bytearray],
encoding: str = "utf-8",
) -> str:
def normalize_uri(uri: t.Union[str, bytes], encoding: str = "utf-8") -> str:
"""Normalize the given URI.
This is a convenience function. You could use either
Expand All @@ -106,10 +103,7 @@ def normalize_uri(
return normalized_reference.unsplit()


def urlparse(
uri: t.Union[str, bytes, bytearray],
encoding: str = "utf-8",
) -> ParseResult:
def urlparse(uri: t.Union[str, bytes], encoding: str = "utf-8") -> ParseResult:
"""Parse a given URI and return a ParseResult.
This is a partial replacement of the standard library's urlparse function.
Expand Down
8 changes: 4 additions & 4 deletions src/rfc3986/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@t.overload
def to_str( # noqa: D103
b: t.Union[str, bytes, bytearray],
b: t.Union[str, bytes],
encoding: str = "utf-8",
) -> str:
...
Expand All @@ -34,7 +34,7 @@ def to_str(b: None, encoding: str = "utf-8") -> None: # noqa: D103


def to_str(
b: t.Optional[t.Union[str, bytes, bytearray]],
b: t.Optional[t.Union[str, bytes]],
encoding: str = "utf-8",
) -> t.Optional[str]:
"""Ensure that b is text in the specified encoding."""
Expand All @@ -45,7 +45,7 @@ def to_str(

@t.overload
def to_bytes( # noqa: D103
s: t.Union[str, bytes, bytearray],
s: t.Union[str, bytes],
encoding: str = "utf-8",
) -> bytes:
...
Expand All @@ -57,7 +57,7 @@ def to_bytes(s: None, encoding: str = "utf-8") -> None: # noqa: D103


def to_bytes(
s: t.Optional[t.Union[str, bytes, bytearray]],
s: t.Optional[t.Union[str, bytes]],
encoding: str = "utf-8",
) -> t.Optional[bytes]:
"""Ensure that s is converted to bytes from the encoding."""
Expand Down
2 changes: 1 addition & 1 deletion src/rfc3986/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _match_subauthority(self) -> t.Optional[t.Match[str]]:
@classmethod
def from_string(
cls,
iri_string: t.Union[str, bytes, bytearray],
iri_string: t.Union[str, bytes],
encoding: str = "utf-8",
) -> Self:
"""Parse a IRI reference from the given unicode IRI string.
Expand Down
2 changes: 1 addition & 1 deletion src/rfc3986/parseresult.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def from_parts(
@classmethod
def from_string(
cls,
uri_string: t.Union[str, bytes, bytearray],
uri_string: t.Union[str, bytes],
encoding: str = "utf-8",
strict: bool = True,
lazy_normalize: bool = True,
Expand Down
2 changes: 1 addition & 1 deletion src/rfc3986/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def normalize(self) -> "URIReference":
@classmethod
def from_string(
cls,
uri_string: t.Union[str, bytes, bytearray],
uri_string: t.Union[str, bytes],
encoding: str = "utf-8",
) -> Self:
"""Parse a URI reference from the given unicode URI string.
Expand Down

0 comments on commit f4d150f

Please sign in to comment.