From fbf21995e310f8fb8a71ea2478005ab22afca51a Mon Sep 17 00:00:00 2001 From: hatal175 Date: Sun, 18 Apr 2021 19:30:00 +0300 Subject: [PATCH] Various stubtest fixes (#5230) --- stdlib/random.pyi | 6 +++-- stdlib/re.pyi | 8 +----- stdlib/runpy.pyi | 2 +- stdlib/shutil.pyi | 6 ++++- stdlib/smtpd.pyi | 20 ++++++++++++-- stdlib/smtplib.pyi | 2 +- stdlib/sqlite3/dbapi2.pyi | 4 +-- stdlib/sre_constants.pyi | 2 +- stdlib/sunau.pyi | 5 +--- tests/stubtest_whitelists/py36.txt | 1 + tests/stubtest_whitelists/py37.txt | 1 + tests/stubtest_whitelists/py38.txt | 1 + tests/stubtest_whitelists/py39.txt | 1 + tests/stubtest_whitelists/py3_common.txt | 33 ++++++------------------ 14 files changed, 46 insertions(+), 46 deletions(-) diff --git a/stdlib/random.pyi b/stdlib/random.pyi index f749154c6..0f1e28049 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -1,7 +1,7 @@ import _random import sys from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set -from typing import Any, Optional, Tuple, TypeVar, Union +from typing import Any, NoReturn, Optional, Tuple, TypeVar, Union _T = TypeVar("_T") @@ -45,7 +45,9 @@ class Random(_random.Random): def weibullvariate(self, alpha: float, beta: float) -> float: ... # SystemRandom is not implemented for all OS's; good on Windows & Linux -class SystemRandom(Random): ... +class SystemRandom(Random): + def getstate(self, *args: Any, **kwds: Any) -> NoReturn: ... + def setstate(self, *args: Any, **kwds: Any) -> NoReturn: ... # ----- random function stubs ----- def seed(a: Any = ..., version: int = ...) -> None: ... diff --git a/stdlib/re.pyi b/stdlib/re.pyi index 264174440..e690e7658 100644 --- a/stdlib/re.pyi +++ b/stdlib/re.pyi @@ -1,5 +1,6 @@ import enum import sys +from sre_constants import error as error from typing import Any, AnyStr, Callable, Iterator, List, Optional, Tuple, Union, overload # ----- re variables and constants ----- @@ -50,13 +51,6 @@ if sys.version_info < (3, 7): # undocumented _pattern_type: type -class error(Exception): - msg: str - pattern: str - pos: Optional[int] - lineno: Optional[int] - colno: Optional[int] - @overload def compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]: ... @overload diff --git a/stdlib/runpy.pyi b/stdlib/runpy.pyi index c5eceab87..d40c3668a 100644 --- a/stdlib/runpy.pyi +++ b/stdlib/runpy.pyi @@ -19,4 +19,4 @@ class _ModifiedArgv0: def run_module( mod_name: str, init_globals: Optional[Dict[str, Any]] = ..., run_name: Optional[str] = ..., alter_sys: bool = ... ) -> Dict[str, Any]: ... -def run_path(path_name: str, init_globals: Optional[Dict[str, Any]] = ..., run_name: str = ...) -> Dict[str, Any]: ... +def run_path(path_name: str, init_globals: Optional[Dict[str, Any]] = ..., run_name: Optional[str] = ...) -> Dict[str, Any]: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index b814112a1..c0779d871 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -159,7 +159,11 @@ if sys.version_info >= (3,): # See http://bugs.python.org/issue30218 def unpack_archive(filename: str, extract_dir: Optional[StrPath] = ..., format: Optional[str] = ...) -> None: ... def register_unpack_format( - name: str, extensions: List[str], function: Any, extra_args: Sequence[Tuple[str, Any]] = ..., description: str = ... + name: str, + extensions: List[str], + function: Any, + extra_args: Optional[Sequence[Tuple[str, Any]]] = ..., + description: str = ..., ) -> None: ... def unregister_unpack_format(name: str) -> None: ... def get_unpack_formats() -> List[Tuple[str, List[str], str]]: ... diff --git a/stdlib/smtpd.pyi b/stdlib/smtpd.pyi index e66d02fc2..a4f9bfa65 100644 --- a/stdlib/smtpd.pyi +++ b/stdlib/smtpd.pyi @@ -84,5 +84,21 @@ class SMTPServer(asyncore.dispatcher): ) -> Optional[str]: ... class DebuggingServer(SMTPServer): ... -class PureProxy(SMTPServer): ... -class MailmanProxy(PureProxy): ... + +class PureProxy(SMTPServer): + def process_message( # type: ignore + self, + peer: _Address, + mailfrom: str, + rcpttos: List[Text], + data: Union[bytes, str], + ) -> Optional[str]: ... + +class MailmanProxy(PureProxy): + def process_message( # type: ignore + self, + peer: _Address, + mailfrom: str, + rcpttos: List[Text], + data: Union[bytes, str], + ) -> Optional[str]: ... diff --git a/stdlib/smtplib.pyi b/stdlib/smtplib.pyi index fa9d37e40..4f376d2b6 100644 --- a/stdlib/smtplib.pyi +++ b/stdlib/smtplib.pyi @@ -124,7 +124,7 @@ class SMTP: msg: _Message, from_addr: Optional[str] = ..., to_addrs: Optional[Union[str, Sequence[str]]] = ..., - mail_options: List[str] = ..., + mail_options: Sequence[str] = ..., rcpt_options: Sequence[str] = ..., ) -> _SendErrs: ... def close(self) -> None: ... diff --git a/stdlib/sqlite3/dbapi2.pyi b/stdlib/sqlite3/dbapi2.pyi index ae3b01bfb..51def5406 100644 --- a/stdlib/sqlite3/dbapi2.pyi +++ b/stdlib/sqlite3/dbapi2.pyi @@ -16,7 +16,7 @@ def DateFromTicks(ticks: float) -> Date: ... def TimeFromTicks(ticks: float) -> Time: ... def TimestampFromTicks(ticks: float) -> Timestamp: ... -version_info: str +version_info: Tuple[int, int, int] sqlite_version_info: Tuple[int, int, int] if sys.version_info >= (3,): Binary = memoryview @@ -289,7 +289,7 @@ class Row(object): def __hash__(self): ... def __iter__(self): ... def __le__(self, other): ... - def __len__(self, *args: Any, **kwargs: Any): ... + def __len__(self): ... def __lt__(self, other): ... def __ne__(self, other): ... diff --git a/stdlib/sre_constants.pyi b/stdlib/sre_constants.pyi index 2b411d5c6..d66f19eda 100644 --- a/stdlib/sre_constants.pyi +++ b/stdlib/sre_constants.pyi @@ -8,7 +8,7 @@ class error(Exception): pos: Optional[int] lineno: int colno: int - def __init__(self, msg: str, pattern: Union[str, bytes] = ..., pos: int = ...) -> None: ... + def __init__(self, msg: str, pattern: Optional[Union[str, bytes]] = ..., pos: Optional[int] = ...) -> None: ... class _NamedIntConstant(int): name: Any diff --git a/stdlib/sunau.pyi b/stdlib/sunau.pyi index 9d2f6ec17..175068861 100644 --- a/stdlib/sunau.pyi +++ b/stdlib/sunau.pyi @@ -66,14 +66,11 @@ class Au_write: def getframerate(self) -> int: ... def setnframes(self, nframes: int) -> None: ... def getnframes(self) -> int: ... - def setcomptype(self, comptype: str, compname: str) -> None: ... + def setcomptype(self, type: str, name: str) -> None: ... def getcomptype(self) -> str: ... def getcompname(self) -> str: ... def setparams(self, params: _sunau_params) -> None: ... def getparams(self) -> _sunau_params: ... - def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... - def getmark(self, id: Any) -> NoReturn: ... - def getmarkers(self) -> None: ... def tell(self) -> int: ... # should be any bytes-like object after 3.4, but we don't have a type for that def writeframesraw(self, data: bytes) -> None: ... diff --git a/tests/stubtest_whitelists/py36.txt b/tests/stubtest_whitelists/py36.txt index 95807fe25..ce1b011eb 100644 --- a/tests/stubtest_whitelists/py36.txt +++ b/tests/stubtest_whitelists/py36.txt @@ -37,6 +37,7 @@ plistlib.Dict.__init__ pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args random.Random.randrange # missing undocumented arg _int random.randrange # missing undocumented arg _int +sched.Event.__doc__ # __slots__ is overridden secrets.SystemRandom.getstate smtplib.SMTP.sendmail sre_compile.dis diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index 973768a43..e47b5ff4b 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -47,6 +47,7 @@ pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - funct queue.SimpleQueue.__init__ random.Random.randrange # missing undocumented arg _int random.randrange # missing undocumented arg _int +sched.Event.__doc__ # __slots__ is overridden secrets.SystemRandom.getstate smtplib.SMTP.sendmail sre_constants.RANGE_IGNORE diff --git a/tests/stubtest_whitelists/py38.txt b/tests/stubtest_whitelists/py38.txt index 0afd7e6b9..e2cb0be85 100644 --- a/tests/stubtest_whitelists/py38.txt +++ b/tests/stubtest_whitelists/py38.txt @@ -70,6 +70,7 @@ platform.DEV_NULL queue.SimpleQueue.__init__ random.Random.randrange # missing undocumented arg _int random.randrange # missing undocumented arg _int +sched.Event.__doc__ # __slots__ is overridden secrets.SystemRandom.getstate select.epoll.register smtplib.SMTP.sendmail diff --git a/tests/stubtest_whitelists/py39.txt b/tests/stubtest_whitelists/py39.txt index 214a15847..0b5afd0de 100644 --- a/tests/stubtest_whitelists/py39.txt +++ b/tests/stubtest_whitelists/py39.txt @@ -90,6 +90,7 @@ platform.uname_result.__new__ platform.uname_result._fields platform.uname_result.processor queue.SimpleQueue.__init__ +sched.Event.__doc__ # __slots__ is overridden secrets.SystemRandom.getstate select.epoll.register smtplib.LMTP.__init__ diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 9205731ac..39d737c22 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -213,35 +213,18 @@ pydoc.TextDoc.docmodule pydoc.TextDoc.docother pydoc.TextDoc.docproperty pydoc.TextDoc.docroutine -random.SystemRandom.getstate -re.error.__init__ -runpy.run_path -sched.Event.__doc__ -select.poll -selectors.DevpollSelector -selectors.KqueueSelector -shutil.register_unpack_format -signal.SIGEMT -signal.SIGINFO -smtpd.MailmanProxy.process_message -smtpd.PureProxy.process_message -smtplib.SMTP.send_message -socketserver.BaseServer.fileno -socketserver.BaseServer.get_request -socketserver.BaseServer.server_bind -sqlite3.Row.__len__ -sqlite3.dbapi2.Row.__len__ -sqlite3.dbapi2.version_info -sqlite3.version_info -sre_constants.error.__init__ +select.poll # Depends on configuration +selectors.DevpollSelector # Depends on configuration +selectors.KqueueSelector # Depends on system +signal.SIGEMT # Depends on system +signal.SIGINFO # Depends on system +socketserver.BaseServer.fileno # implemented in derived classes +socketserver.BaseServer.get_request # implemented in derived classes +socketserver.BaseServer.server_bind # implemented in derived classes ssl.PROTOCOL_SSLv2 # Defined only if compiled with ssl v2 ssl.Purpose.__new__ # You cannot override __new__ in NamedTuple and runtime uses namedtuple. ssl._ASN1Object.__new__ # You cannot override __new__ in NamedTuple and runtime uses namedtuple. subprocess.Popen.__init__ -sunau.Au_write.getmark -sunau.Au_write.getmarkers -sunau.Au_write.setcomptype -sunau.Au_write.setmark sys.gettotalrefcount # Available on python debug builds sys.implementation # Actually SimpleNamespace but then you wouldn't have convenient attributes tarfile.TarFile.errors # errors is initialized for some reason as None even though it really only accepts str