diff --git a/.flake8 b/.flake8 index f124e3583..8d1d4a3e8 100644 --- a/.flake8 +++ b/.flake8 @@ -18,9 +18,6 @@ # F405 defined from star imports # Rules that we'd like to enable in the future: -# Y034 Detect common errors where certain methods are annotated as having a fixed -# return type, despite returning self at runtime (temporarily disabled for -# typing.pyi, enabled elsewhere). # Y037 Use PEP 604 syntax instead of `typing.Union` and `typing.Optional`. # Currently can't be enabled due to a few lingering bugs in mypy regarding # PEP 604 type aliases (see #4819). @@ -33,6 +30,6 @@ per-file-ignores = # Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself. # https://github.com/PyCQA/flake8/issues/1079 # F811 redefinition of unused '...' - stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y034, Y037 + stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y037 exclude = .venv*,.git,*_pb2.pyi diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 4739bd410..a186bb92b 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -1,6 +1,7 @@ +import _typeshed import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys -from _typeshed import IdentityFunction, Incomplete, Self as TypeshedSelf, SupportsKeysAndGetItem +from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem from abc import ABCMeta, abstractmethod from contextlib import AbstractAsyncContextManager, AbstractContextManager from re import Match as Match, Pattern as Pattern @@ -496,7 +497,7 @@ class MutableSequence(Sequence[_T], Generic[_T]): def reverse(self) -> None: ... def pop(self, index: int = ...) -> _T: ... def remove(self, value: _T) -> None: ... - def __iadd__(self: TypeshedSelf, values: Iterable[_T]) -> TypeshedSelf: ... + def __iadd__(self: _typeshed.Self, values: Iterable[_T]) -> _typeshed.Self: ... class AbstractSet(Collection[_T_co], Generic[_T_co]): @abstractmethod @@ -522,10 +523,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]): def clear(self) -> None: ... def pop(self) -> _T: ... def remove(self, value: _T) -> None: ... - def __ior__(self: TypeshedSelf, it: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc] - def __iand__(self: TypeshedSelf, it: AbstractSet[Any]) -> TypeshedSelf: ... - def __ixor__(self: TypeshedSelf, it: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc] - def __isub__(self: TypeshedSelf, it: AbstractSet[Any]) -> TypeshedSelf: ... + def __ior__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] + def __iand__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... + def __ixor__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] + def __isub__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... class MappingView(Sized): def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented @@ -778,7 +779,7 @@ class NamedTuple(tuple[Any, ...]): else: def _asdict(self) -> collections.OrderedDict[str, Any]: ... - def _replace(self: TypeshedSelf, **kwargs: Any) -> TypeshedSelf: ... + def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... # Internal mypy fallback type for all typed dicts (does not exist at runtime) # N.B. Keep this mostly in sync with typing_extensions._TypedDict/mypy_extensions._TypedDict @@ -788,7 +789,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): if sys.version_info >= (3, 9): __required_keys__: ClassVar[frozenset[str]] __optional_keys__: ClassVar[frozenset[str]] - def copy(self: TypeshedSelf) -> TypeshedSelf: ... + def copy(self: _typeshed.Self) -> _typeshed.Self: ... # Using NoReturn so that only calls using mypy plugin hook that specialize the signature # can go through. def setdefault(self, k: NoReturn, default: object) -> object: ... @@ -800,8 +801,8 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def keys(self) -> KeysView[str]: ... def values(self) -> ValuesView[object]: ... if sys.version_info >= (3, 9): - def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... - def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ... + def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... + def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... @_final class ForwardRef: