Skip to content

Commit

Permalink
urllib.parse: extend unquote type hint and replace _Str with str | by…
Browse files Browse the repository at this point in the history
…tes (#8877)
  • Loading branch information
gruebel authored Oct 14, 2022
1 parent f07e68d commit ccd468f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions stdlib/urllib/parse.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from collections.abc import Callable, Mapping, Sequence
from typing import Any, AnyStr, Generic, NamedTuple, overload
from typing_extensions import TypeAlias

if sys.version_info >= (3, 9):
from types import GenericAlias
Expand Down Expand Up @@ -30,8 +29,6 @@ __all__ = [
"SplitResultBytes",
]

_Str: TypeAlias = bytes | str

uses_relative: list[str]
uses_netloc: list[str]
uses_params: list[str]
Expand Down Expand Up @@ -135,16 +132,22 @@ def parse_qsl(
separator: str = ...,
) -> list[tuple[AnyStr, AnyStr]]: ...
@overload
def quote(string: str, safe: _Str = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
def quote(string: str, safe: str | bytes = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
@overload
def quote(string: bytes, safe: _Str = ...) -> str: ...
def quote_from_bytes(bs: bytes, safe: _Str = ...) -> str: ...
def quote(string: bytes, safe: str | bytes = ...) -> str: ...
def quote_from_bytes(bs: bytes, safe: str | bytes = ...) -> str: ...
@overload
def quote_plus(string: str, safe: _Str = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
def quote_plus(string: str, safe: str | bytes = ..., encoding: str | None = ..., errors: str | None = ...) -> str: ...
@overload
def quote_plus(string: bytes, safe: _Str = ...) -> str: ...
def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ...
def unquote_to_bytes(string: _Str) -> bytes: ...
def quote_plus(string: bytes, safe: str | bytes = ...) -> str: ...

if sys.version_info >= (3, 9):
def unquote(string: str | bytes, encoding: str = ..., errors: str = ...) -> str: ...

else:
def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ...

def unquote_to_bytes(string: str | bytes) -> bytes: ...
def unquote_plus(string: str, encoding: str = ..., errors: str = ...) -> str: ...
@overload
def urldefrag(url: str) -> DefragResult: ...
Expand All @@ -153,10 +156,10 @@ def urldefrag(url: bytes | None) -> DefragResultBytes: ...
def urlencode(
query: Mapping[Any, Any] | Mapping[Any, Sequence[Any]] | Sequence[tuple[Any, Any]] | Sequence[tuple[Any, Sequence[Any]]],
doseq: bool = ...,
safe: _Str = ...,
safe: str | bytes = ...,
encoding: str = ...,
errors: str = ...,
quote_via: Callable[[AnyStr, _Str, str, str], str] = ...,
quote_via: Callable[[AnyStr, str | bytes, str, str], str] = ...,
) -> str: ...
def urljoin(base: AnyStr, url: AnyStr | None, allow_fragments: bool = ...) -> AnyStr: ...
@overload
Expand Down

0 comments on commit ccd468f

Please sign in to comment.