Fix stubtest complaints for various .get() methods (#10690)

This commit is contained in:
Alex Waygood
2023-09-10 22:48:09 +01:00
committed by GitHub
parent 011b5b9c2c
commit 6dda2fe9c8
4 changed files with 17 additions and 4 deletions

View File

@@ -96,6 +96,11 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
@overload
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
if sys.version_info >= (3, 12):
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
class UserList(MutableSequence[_T]):
data: list[_T]
@@ -422,6 +427,10 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
def __contains__(self, key: object) -> bool: ...
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
def __missing__(self, key: _KT) -> _VT: ... # undocumented
def __bool__(self) -> bool: ...
# Keep ChainMap.setdefault in line with MutableMapping.setdefault, modulo positional-only differences.

View File

@@ -65,6 +65,10 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]):
def copy(self) -> WeakValueDictionary[_KT, _VT]: ...
__copy__ = copy
def __deepcopy__(self, memo: Any) -> Self: ...
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
# These are incompatible with Mapping
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
def values(self) -> Iterator[_VT]: ... # type: ignore[override]
@@ -107,6 +111,10 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]):
def copy(self) -> WeakKeyDictionary[_KT, _VT]: ...
__copy__ = copy
def __deepcopy__(self, memo: Any) -> Self: ...
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
# These are incompatible with Mapping
def keys(self) -> Iterator[_KT]: ... # type: ignore[override]
def values(self) -> Iterator[_VT]: ... # type: ignore[override]

View File

@@ -1,5 +1,4 @@
# Uncategorised, from Python 3.12
collections.UserDict.get
enum.Enum.__signature__
enum.EnumMeta.__call__
enum.EnumType.__call__

View File

@@ -26,7 +26,6 @@ asyncio.futures.Future.__init__ # Usually initialized from c object
builtins.dict.get
builtins.ellipsis # type is not exposed anywhere
builtins.function
collections.ChainMap.get # Adding None to the underlying Mapping Union messed up mypy
collections.ChainMap.fromkeys # Runtime has *args which can really only be one argument
collections.UserList.sort # Runtime has *args but will error if any are supplied
configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used
@@ -129,9 +128,7 @@ typing(_extensions)?\.IO\.__next__ # Added because IO streams are iterable. See
typing.type_check_only # typing decorator that is not available at runtime
unittest.mock.patch # It's a complicated overload and I haven't been able to figure out why stubtest doesn't like it
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified
weakref.WeakKeyDictionary.get
weakref.WeakKeyDictionary.update
weakref.WeakValueDictionary.get
weakref.WeakValueDictionary.update
xml.etree.ElementTree.XMLParser.__init__ # Defined in C so has general signature
xml.etree.cElementTree.XMLParser.__init__ # Defined in C so has general signature