From d151d1b8bb4bd94777c05f9e0949fbb63bac8df5 Mon Sep 17 00:00:00 2001 From: hatal175 Date: Mon, 26 Apr 2021 07:56:54 +0300 Subject: [PATCH] Stubtest fixes (#5249) --- stdlib/abc.pyi | 2 +- stdlib/collections/__init__.pyi | 10 ++--- tests/stubtest_whitelists/py3_common.txt | 51 ++++++++---------------- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/stdlib/abc.pyi b/stdlib/abc.pyi index 6be75c3bc..5dd21763a 100644 --- a/stdlib/abc.pyi +++ b/stdlib/abc.pyi @@ -7,7 +7,7 @@ _FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) class ABCMeta(type): def register(cls: ABCMeta, subclass: Type[_T]) -> Type[_T]: ... -def abstractmethod(callable: _FuncT) -> _FuncT: ... +def abstractmethod(funcobj: _FuncT) -> _FuncT: ... class abstractproperty(property): ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index 76ec87661..635d32ebd 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload +from typing import Any, Dict, Generic, List, NoReturn, Optional, Tuple, Type, TypeVar, Union, overload if sys.version_info >= (3, 10): from typing import ( @@ -190,7 +190,6 @@ class deque(MutableSequence[_T], Generic[_T]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... def __str__(self) -> str: ... - def __hash__(self) -> int: ... # These methods of deque don't really take slices, but we need to # define them as taking a slice to satisfy MutableSequence. @overload @@ -222,6 +221,8 @@ class Counter(Dict[_T, int], Generic[_T]): def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... + @classmethod + def fromkeys(cls, iterable: Any, v: Optional[int] = ...) -> NoReturn: ... # type: ignore @overload def subtract(self, __iterable: None = ...) -> None: ... @overload @@ -291,10 +292,9 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def copy(self: _S) -> _S: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + maps: List[Mapping[_KT, _VT]] def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... - @property - def maps(self) -> List[Mapping[_KT, _VT]]: ... - def new_child(self, m: Mapping[_KT, _VT] = ...) -> ChainMap[_KT, _VT]: ... + def new_child(self, m: Optional[Mapping[_KT, _VT]] = ...) -> ChainMap[_KT, _VT]: ... @property def parents(self) -> ChainMap[_KT, _VT]: ... def __setitem__(self, k: _KT, v: _VT) -> None: ... diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index b4056470f..a81a9c1a1 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -1,4 +1,5 @@ -_collections_abc.Callable +_collections_abc.Callable # Some typecheckers need this as specialform +# Coroutine and Generator properties are added programmatically _collections_abc.Coroutine.cr_await _collections_abc.Coroutine.cr_code _collections_abc.Coroutine.cr_frame @@ -7,31 +8,19 @@ _collections_abc.Generator.gi_code _collections_abc.Generator.gi_frame _collections_abc.Generator.gi_running _collections_abc.Generator.gi_yieldfrom -_collections_abc.Mapping.get -_collections_abc.MutableMapping.pop -_collections_abc.MutableMapping.setdefault -_collections_abc.MutableSequence.append -_collections_abc.MutableSequence.extend -_collections_abc.MutableSequence.insert -_collections_abc.MutableSequence.remove -_collections_abc.MutableSet.add -_collections_abc.MutableSet.discard -_collections_abc.MutableSet.remove -_collections_abc.Sequence.count -_collections_abc.Sequence.index -_collections_abc.Set.isdisjoint +_collections_abc.Mapping.get # Adding None to the Union messed up mypy +_collections_abc.Sequence.index # Supporting None in end is not mandatory _csv.Dialect.__init__ # C __init__ signature is inaccurate _dummy_threading _importlib_modulespec _threading_local.local.__new__ _typeshed.* # Utility types for typeshed, doesn't exist at runtime -_weakref.CallableProxyType.__getattr__ -_weakref.ProxyType.__getattr__ -_weakref.ReferenceType.__call__ -abc.ABCMeta.__new__ abc.abstractclassmethod -abc.abstractmethod abc.abstractstaticmethod +abc.ABCMeta.__new__ # pytype wants the parameter named cls and not mcls +_weakref.CallableProxyType.__getattr__ # Should have all attributes of proxy +_weakref.ProxyType.__getattr__ # Should have all attributes of proxy +_weakref.ReferenceType.__call__ # C function default annotation is wrong argparse.Namespace.__getattr__ # The whole point of this class is its attributes are dynamic asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them # Condition functions are exported in __init__ @@ -69,23 +58,20 @@ codecs.CodecInfo.incrementaldecoder codecs.CodecInfo.incrementalencoder codecs.CodecInfo.streamreader codecs.CodecInfo.streamwriter -collections.Callable -collections.ChainMap.get -collections.ChainMap.maps -collections.ChainMap.new_child +collections.Callable # Some typecheckers need this as specialform +# Coroutine and Generator properties are added programmatically +collections.ChainMap.get # Adding None to the underlying Mapping Union messed up mypy collections.Coroutine.cr_await collections.Coroutine.cr_code collections.Coroutine.cr_frame collections.Coroutine.cr_running -collections.Counter.fromkeys collections.Generator.gi_code collections.Generator.gi_frame collections.Generator.gi_running collections.Generator.gi_yieldfrom -collections.Mapping.get -collections.Sequence.index -collections.Set.isdisjoint -collections.abc.Callable +collections.Mapping.get # Adding None to the Union messed up mypy +collections.Sequence.index # Supporting None in end is not mandatory +# Coroutine and Generator properties are added programmatically collections.abc.Coroutine.cr_await collections.abc.Coroutine.cr_code collections.abc.Coroutine.cr_frame @@ -94,9 +80,6 @@ collections.abc.Generator.gi_code collections.abc.Generator.gi_frame collections.abc.Generator.gi_running collections.abc.Generator.gi_yieldfrom -collections.abc.Mapping.get -collections.abc.Sequence.index -collections.deque.__hash__ configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used # SectionProxy get functions are set in __init__ configparser.SectionProxy.getboolean @@ -254,9 +237,9 @@ urllib.request.BaseHandler.http_error_nnn urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ urllib.robotparser.RobotFileParser.can_fetch warnings.catch_warnings.__init__ # Defining this ruins the __new__ overrides -weakref.CallableProxyType.__getattr__ -weakref.ProxyType.__getattr__ -weakref.ReferenceType.__call__ +weakref.CallableProxyType.__getattr__ # Should have all attributes of proxy +weakref.ProxyType.__getattr__ # Should have all attributes of proxy +weakref.ReferenceType.__call__ # C function default annotation is wrong weakref.WeakKeyDictionary.get weakref.WeakKeyDictionary.update weakref.WeakValueDictionary.get