Skip to content

Commit f4d150f

Browse files
Fix: Removing the bytearray hints. Sticking to bytes and str is simpler 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.
1 parent d99f274 commit f4d150f

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

src/rfc3986/api.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

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

4343

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

6060

6161
def is_valid_uri(
62-
uri: t.Union[str, bytes, bytearray],
62+
uri: t.Union[str, bytes],
6363
encoding: str = "utf-8",
6464
**kwargs: bool,
6565
) -> bool:
@@ -87,10 +87,7 @@ def is_valid_uri(
8787
return URIReference.from_string(uri, encoding).is_valid(**kwargs)
8888

8989

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

108105

109-
def urlparse(
110-
uri: t.Union[str, bytes, bytearray],
111-
encoding: str = "utf-8",
112-
) -> ParseResult:
106+
def urlparse(uri: t.Union[str, bytes], encoding: str = "utf-8") -> ParseResult:
113107
"""Parse a given URI and return a ParseResult.
114108
115109
This is a partial replacement of the standard library's urlparse function.

src/rfc3986/compat.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
@t.overload
2424
def to_str( # noqa: D103
25-
b: t.Union[str, bytes, bytearray],
25+
b: t.Union[str, bytes],
2626
encoding: str = "utf-8",
2727
) -> str:
2828
...
@@ -34,7 +34,7 @@ def to_str(b: None, encoding: str = "utf-8") -> None: # noqa: D103
3434

3535

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

4646
@t.overload
4747
def to_bytes( # noqa: D103
48-
s: t.Union[str, bytes, bytearray],
48+
s: t.Union[str, bytes],
4949
encoding: str = "utf-8",
5050
) -> bytes:
5151
...
@@ -57,7 +57,7 @@ def to_bytes(s: None, encoding: str = "utf-8") -> None: # noqa: D103
5757

5858

5959
def to_bytes(
60-
s: t.Optional[t.Union[str, bytes, bytearray]],
60+
s: t.Optional[t.Union[str, bytes]],
6161
encoding: str = "utf-8",
6262
) -> t.Optional[bytes]:
6363
"""Ensure that s is converted to bytes from the encoding."""

src/rfc3986/iri.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _match_subauthority(self) -> t.Optional[t.Match[str]]:
8989
@classmethod
9090
def from_string(
9191
cls,
92-
iri_string: t.Union[str, bytes, bytearray],
92+
iri_string: t.Union[str, bytes],
9393
encoding: str = "utf-8",
9494
) -> Self:
9595
"""Parse a IRI reference from the given unicode IRI string.

src/rfc3986/parseresult.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def from_parts(
157157
@classmethod
158158
def from_string(
159159
cls,
160-
uri_string: t.Union[str, bytes, bytearray],
160+
uri_string: t.Union[str, bytes],
161161
encoding: str = "utf-8",
162162
strict: bool = True,
163163
lazy_normalize: bool = True,

src/rfc3986/uri.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def normalize(self) -> "URIReference":
149149
@classmethod
150150
def from_string(
151151
cls,
152-
uri_string: t.Union[str, bytes, bytearray],
152+
uri_string: t.Union[str, bytes],
153153
encoding: str = "utf-8",
154154
) -> Self:
155155
"""Parse a URI reference from the given unicode URI string.

0 commit comments

Comments
 (0)