From ccd468fd867e9ce8b690af441ee72e82529af345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Gr=C3=BCbel?= Date: Fri, 14 Oct 2022 05:54:07 +0200 Subject: [PATCH] urllib.parse: extend unquote type hint and replace _Str with str | bytes (#8877) --- stdlib/urllib/parse.pyi | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/stdlib/urllib/parse.pyi b/stdlib/urllib/parse.pyi index 7e1ec903a15e..207a05e75a57 100644 --- a/stdlib/urllib/parse.pyi +++ b/stdlib/urllib/parse.pyi @@ -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 @@ -30,8 +29,6 @@ __all__ = [ "SplitResultBytes", ] -_Str: TypeAlias = bytes | str - uses_relative: list[str] uses_netloc: list[str] uses_params: list[str] @@ -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: ... @@ -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