From c70cffd61acfd7c74844c8647d47c46084430896 Mon Sep 17 00:00:00 2001 From: "Schweizer, Robert" Date: Wed, 25 Sep 2019 16:09:19 +0200 Subject: [PATCH] Add missing Optional types in urllib.parse None values are accepted, and interpreted as empty (byte) strings by some urllib.parse functions. This is probably not the desired behavior, but can be useful especially when passing through values that default to None in outside functions. Signed-off-by: Schweizer, Robert --- stdlib/3/urllib/parse.pyi | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index b835119ec890..fde62b64723c 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -81,9 +81,9 @@ class SplitResultBytes(_SplitResultBytesBase, _NetlocResultMixinBytes): ... class ParseResultBytes(_ParseResultBytesBase, _NetlocResultMixinBytes): ... -def parse_qs(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> Dict[AnyStr, List[AnyStr]]: ... +def parse_qs(qs: Optional[AnyStr], keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> Dict[AnyStr, List[AnyStr]]: ... -def parse_qsl(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> List[Tuple[AnyStr, AnyStr]]: ... +def parse_qsl(qs: Optional[AnyStr], keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> List[Tuple[AnyStr, AnyStr]]: ... @overload @@ -107,7 +107,7 @@ def unquote_plus(string: str, encoding: str = ..., errors: str = ...) -> str: .. @overload def urldefrag(url: str) -> DefragResult: ... @overload -def urldefrag(url: bytes) -> DefragResultBytes: ... +def urldefrag(url: Optional[bytes]) -> DefragResultBytes: ... def urlencode( query: Union[Mapping[Any, Any], Mapping[Any, Sequence[Any]], Sequence[Tuple[Any, Any]], Sequence[Tuple[Any, Sequence[Any]]]], @@ -121,21 +121,23 @@ def urlencode( def urljoin(base: AnyStr, url: Optional[AnyStr], allow_fragments: bool = ...) -> AnyStr: ... @overload -def urlparse(url: str, scheme: str = ..., allow_fragments: bool = ...) -> ParseResult: ... +def urlparse(url: str, scheme: Optional[str] = ..., allow_fragments: bool = ...) -> ParseResult: ... @overload -def urlparse(url: bytes, scheme: bytes = ..., allow_fragments: bool = ...) -> ParseResultBytes: ... +def urlparse(url: Optional[bytes], scheme: Optional[bytes] = ..., allow_fragments: bool = ...) -> ParseResultBytes: ... @overload -def urlsplit(url: str, scheme: str = ..., allow_fragments: bool = ...) -> SplitResult: ... +def urlsplit(url: str, scheme: Optional[str] = ..., allow_fragments: bool = ...) -> SplitResult: ... @overload -def urlsplit(url: bytes, scheme: bytes = ..., allow_fragments: bool = ...) -> SplitResultBytes: ... +def urlsplit(url: Optional[bytes], scheme: Optional[bytes] = ..., allow_fragments: bool = ...) -> SplitResultBytes: ... @overload -def urlunparse(components: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ... +def urlunparse( + components: Tuple[Optional[AnyStr], Optional[AnyStr], Optional[AnyStr], Optional[AnyStr], Optional[AnyStr], Optional[AnyStr]] +) -> AnyStr: ... @overload -def urlunparse(components: Sequence[AnyStr]) -> AnyStr: ... +def urlunparse(components: Sequence[Optional[AnyStr]]) -> AnyStr: ... @overload -def urlunsplit(components: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ... +def urlunsplit(components: Tuple[Optional[AnyStr], Optional[AnyStr], Optional[AnyStr], Optional[AnyStr], Optional[AnyStr]]) -> AnyStr: ... @overload -def urlunsplit(components: Sequence[AnyStr]) -> AnyStr: ... +def urlunsplit(components: Sequence[Optional[AnyStr]]) -> AnyStr: ...