diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 954e451ce..24faea28b 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -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: ... diff --git a/stdlib/collections/__init__.pyi b/stdlib/collections/__init__.pyi index 5b2fedf89..8c6191e68 100644 --- a/stdlib/collections/__init__.pyi +++ b/stdlib/collections/__init__.pyi @@ -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 diff --git a/stdlib/contextvars.pyi b/stdlib/contextvars.pyi index d85285127..38c5d5ed7 100644 --- a/stdlib/contextvars.pyi +++ b/stdlib/contextvars.pyi @@ -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: ... diff --git a/stdlib/io.pyi b/stdlib/io.pyi index 7b9951dbe..659248015 100644 --- a/stdlib/io.pyi +++ b/stdlib/io.pyi @@ -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: ... diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 9a6bd37ea..b6edd3ac8 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -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 diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index bd5ae6852..eab80f445 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -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