Fix various pos-only stubtest complaints previously allowlisted (#7228)

This commit is contained in:
Alex Waygood
2022-02-15 16:51:34 +00:00
committed by GitHub
parent 1317fa7af9
commit 5e8a2a9364
6 changed files with 19 additions and 15 deletions

View File

@@ -604,6 +604,8 @@ class bytearray(MutableSequence[int], ByteString):
def lower(self) -> bytearray: ...
def lstrip(self, __bytes: bytes | None = ...) -> bytearray: ...
def partition(self, __sep: bytes) -> tuple[bytearray, bytearray, bytearray]: ...
def pop(self, __index: int = ...) -> int: ...
def remove(self, __value: int) -> None: ...
if sys.version_info >= (3, 9):
def removeprefix(self, __prefix: bytes) -> bytearray: ...
def removesuffix(self, __suffix: bytes) -> bytearray: ...

View File

@@ -304,15 +304,20 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
def keys(self) -> _OrderedDictKeysView[_KT, _VT]: ...
def items(self) -> _OrderedDictItemsView[_KT, _VT]: ...
def values(self) -> _OrderedDictValuesView[_KT, _VT]: ...
# `fromkeys` is actually inherited from `dict` at runtime, so the signature should be kept in line with `dict.fromkeys`.
# Ideally we would not redefine it here, but the true signature of `dict.fromkeys` is not expressible in the current type system.
# The signature of OrderedDict.fromkeys should be kept in line with `dict.fromkeys`, modulo positional-only differences.
# Like dict.fromkeys, its true signature is not expressible in the current type system.
# See #3800 & https://github.com/python/typing/issues/548#issuecomment-683336963.
@classmethod
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: None = ...) -> OrderedDict[_T, Any | None]: ...
def fromkeys(cls, iterable: Iterable[_T], value: None = ...) -> OrderedDict[_T, Any | None]: ...
@classmethod
@overload
def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> OrderedDict[_T, _S]: ...
def fromkeys(cls, iterable: Iterable[_T], value: _S) -> OrderedDict[_T, _S]: ...
# Keep OrderedDict.setdefault in line with MutableMapping.setdefault, modulo positional-only differences.
@overload
def setdefault(self: OrderedDict[_KT, _T | None], key: _KT) -> _T | None: ...
@overload
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
default_factory: Callable[[], _VT] | None

View File

@@ -18,8 +18,8 @@ class ContextVar(Generic[_T]):
def get(self) -> _T: ...
@overload
def get(self, default: _D | _T) -> _D | _T: ...
def set(self, value: _T) -> Token[_T]: ...
def reset(self, token: Token[_T]) -> None: ...
def set(self, __value: _T) -> Token[_T]: ...
def reset(self, __token: Token[_T]) -> None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

View File

@@ -181,3 +181,4 @@ class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
def decode(self, input: bytes | str, final: bool = ...) -> str: ...
@property
def newlines(self) -> str | tuple[str, ...] | None: ...
def setstate(self, __state: tuple[bytes, int]) -> None: ...

View File

@@ -487,6 +487,7 @@ class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]):
def pop(self, __key: _KT, default: _VT | _T) -> _VT | _T: ...
def popitem(self) -> tuple[_KT, _VT]: ...
# This overload should be allowed only if the value type is compatible with None.
# Keep OrderedDict.setdefault in line with MutableMapping.setdefault, modulo positional-only differences.
@overload
def setdefault(self: MutableMapping[_KT, _T | None], __key: _KT) -> _T | None: ...
@overload

View File

@@ -106,11 +106,7 @@ 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
# positional-only complaints
builtins.bytearray.pop
builtins.bytearray.remove
collections.OrderedDict.fromkeys
collections.OrderedDict.setdefault
# positional-only complaints caused by differences between typing aliases and the "real" classes in the stdlib
_collections_abc.AsyncGenerator.asend
_collections_abc.AsyncGenerator.athrow
_collections_abc.Container.__contains__
@@ -118,13 +114,12 @@ _collections_abc.Coroutine.send
_collections_abc.Coroutine.throw
_collections_abc.Generator.send
_collections_abc.Generator.throw
contextvars.ContextVar.reset
contextvars.ContextVar.set
contextlib.AbstractAsyncContextManager.__aexit__
contextlib.AbstractContextManager.__exit__
io.IncrementalNewlineDecoder.setstate
typing.SupportsRound.__round__
typing.SupportsRound.__round__ # pos-or-kw at runtime, but we pretend it's pos-only in the stub so that e.g. float.__round__ satisfies the interface
types.DynamicClassAttribute..* # In the stub we pretend it's an alias for property, but it has positional-only differences
# These three have a pos-or-keyword first parameter at runtime, but deliberately have a pos-only first parameter in the stub. #6812
posixpath.join
ntpath.join