From 7cdc4bfa5ef3bd6d06798d9a7a818692c3f0db6a Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 11 Mar 2019 16:41:11 +0300 Subject: [PATCH 1/4] Making vars argument Optional, as it defaults to None in the code and documentation. --- stdlib/2/ConfigParser.pyi | 6 +++--- stdlib/3/configparser.pyi | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/stdlib/2/ConfigParser.pyi b/stdlib/2/ConfigParser.pyi index 6e6a70e1de1b..693fe3fe1c3a 100644 --- a/stdlib/2/ConfigParser.pyi +++ b/stdlib/2/ConfigParser.pyi @@ -1,4 +1,4 @@ -from typing import Any, IO, Sequence, Tuple, Union, List, Dict, Protocol +from typing import Any, IO, Sequence, Tuple, Union, List, Dict, Protocol, Optional DEFAULTSECT = ... # type: str MAX_INTERPOLATION_DEPTH = ... # type: int @@ -86,8 +86,8 @@ class RawConfigParser: class ConfigParser(RawConfigParser): _KEYCRE = ... # type: Any - def get(self, section: str, option: str, raw: bool = ..., vars: dict = ...) -> Any: ... - def items(self, section: str, raw: bool = ..., vars: dict = ...) -> List[Tuple[str, Any]]: ... + def get(self, section: str, option: str, raw: bool = ..., vars: Optional[dict] = ...) -> Any: ... + def items(self, section: str, raw: bool = ..., vars: Optional[dict] = ...) -> List[Tuple[str, Any]]: ... def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... def _interpolation_replace(self, match: Any) -> str: ... diff --git a/stdlib/3/configparser.pyi b/stdlib/3/configparser.pyi index 2df7b3381bb6..ef62c0673a2d 100644 --- a/stdlib/3/configparser.pyi +++ b/stdlib/3/configparser.pyi @@ -102,23 +102,23 @@ class RawConfigParser(_parser): # These get* methods are partially applied (with the same names) in # SectionProxy; the stubs should be kept updated together - def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ... + def getint(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: int = ...) -> int: ... - def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ... + def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: float = ...) -> float: ... - def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ... + def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: bool = ...) -> bool: ... - def _get_conv(self, section: str, option: str, conv: Callable[[str], _T], *, raw: bool = ..., vars: _section = ..., fallback: _T = ...) -> _T: ... + def _get_conv(self, section: str, option: str, conv: Callable[[str], _T], *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...) -> _T: ... # This is incompatible with MutableMapping so we ignore the type - def get(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: str = ...) -> str: # type: ignore + def get(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: str = ...) -> str: # type: ignore ... @overload - def items(self, *, raw: bool = ..., vars: _section = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ... + def items(self, *, raw: bool = ..., vars: Optional[_section] = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ... @overload - def items(self, section: str, raw: bool = ..., vars: _section = ...) -> List[Tuple[str, str]]: ... + def items(self, section: str, raw: bool = ..., vars: Optional[_section] = ...) -> List[Tuple[str, str]]: ... def set(self, section: str, option: str, value: str) -> None: ... @@ -165,9 +165,9 @@ class SectionProxy(MutableMapping[str, str]): # These are partially-applied version of the methods with the same names in # RawConfigParser; the stubs should be kept updated together - def getint(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ... - def getfloat(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ... - def getboolean(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ... + def getint(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: int = ...) -> int: ... + def getfloat(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: float = ...) -> float: ... + def getboolean(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: bool = ...) -> bool: ... # SectionProxy can have arbitrary attributes when custon converters are used def __getattr__(self, key: str) -> Callable[..., Any]: ... From 3eed4517c6be61a2514b9b40a90f5ceecd8e794d Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 11 Mar 2019 20:07:39 +0300 Subject: [PATCH 2/4] email.charset.SHORTEST, QP, BASE64 are not in the stub for Python 2 --- stdlib/2/email/charset.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/2/email/charset.pyi b/stdlib/2/email/charset.pyi index 82ba6c0bbbc5..b60d77c69667 100644 --- a/stdlib/2/email/charset.pyi +++ b/stdlib/2/email/charset.pyi @@ -2,6 +2,10 @@ def add_charset(charset, header_enc=..., body_enc=..., output_charset=...) -> No def add_alias(alias, canonical) -> None: ... def add_codec(charset, codecname) -> None: ... +QP: int +BASE64: int +SHORTEST: int + class Charset: input_charset = ... header_encoding = ... From d065fdfb5350b8b3ac1560567cd0ec45ab516500 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 11 Mar 2019 20:11:51 +0300 Subject: [PATCH 3/4] email.mime.application.MIMEApplication expects data to be bytes, while it should be Union[str, bytes] Fixes #2831 --- stdlib/3/email/mime/application.pyi | 2 +- stdlib/3/email/mime/audio.pyi | 2 +- stdlib/3/email/mime/image.pyi | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/3/email/mime/application.pyi b/stdlib/3/email/mime/application.pyi index 1aa0580ec891..1a40e281f447 100644 --- a/stdlib/3/email/mime/application.pyi +++ b/stdlib/3/email/mime/application.pyi @@ -6,6 +6,6 @@ from email.mime.nonmultipart import MIMENonMultipart _ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEApplication(MIMENonMultipart): - def __init__(self, _data: bytes, _subtype: str = ..., + def __init__(self, _data: Union[str, bytes], _subtype: str = ..., _encoder: Callable[[MIMEApplication], None] = ..., **_params: _ParamsType) -> None: ... diff --git a/stdlib/3/email/mime/audio.pyi b/stdlib/3/email/mime/audio.pyi index 2d2c90c2af50..5bb57d3a5d7a 100644 --- a/stdlib/3/email/mime/audio.pyi +++ b/stdlib/3/email/mime/audio.pyi @@ -6,6 +6,6 @@ from email.mime.nonmultipart import MIMENonMultipart _ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEAudio(MIMENonMultipart): - def __init__(self, _audiodata: bytes, _subtype: Optional[str] = ..., + def __init__(self, _audiodata: Union[str, bytes], _subtype: Optional[str] = ..., _encoder: Callable[[MIMEAudio], None] = ..., **_params: _ParamsType) -> None: ... diff --git a/stdlib/3/email/mime/image.pyi b/stdlib/3/email/mime/image.pyi index 9ec5deba0916..d32d9ee650fc 100644 --- a/stdlib/3/email/mime/image.pyi +++ b/stdlib/3/email/mime/image.pyi @@ -6,6 +6,6 @@ from email.mime.nonmultipart import MIMENonMultipart _ParamsType = Union[str, None, Tuple[str, Optional[str], str]] class MIMEImage(MIMENonMultipart): - def __init__(self, _imagedata: bytes, _subtype: Optional[str] = ..., + def __init__(self, _imagedata: Union[str, bytes], _subtype: Optional[str] = ..., _encoder: Callable[[MIMEImage], None] = ..., **_params: _ParamsType) -> None: ... From 73e625fe0de2e69d41cb76019cd8363bb7f0a402 Mon Sep 17 00:00:00 2001 From: Vasily Zakharov Date: Mon, 11 Mar 2019 20:42:05 +0300 Subject: [PATCH 4/4] Adding #undocumented as requested by @srittau to fix #2830 --- stdlib/2/email/charset.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/2/email/charset.pyi b/stdlib/2/email/charset.pyi index b60d77c69667..53c9166fba53 100644 --- a/stdlib/2/email/charset.pyi +++ b/stdlib/2/email/charset.pyi @@ -2,9 +2,9 @@ def add_charset(charset, header_enc=..., body_enc=..., output_charset=...) -> No def add_alias(alias, canonical) -> None: ... def add_codec(charset, codecname) -> None: ... -QP: int -BASE64: int -SHORTEST: int +QP: int # undocumented +BASE64: int # undocumented +SHORTEST: int # undocumented class Charset: input_charset = ...