Skip to content

Commit 556f6a1

Browse files
authored
Enable flake8-pyi's Y034 check in stdlib/typing.pyi (#8530)
1 parent 5a24bf8 commit 556f6a1

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

.flake8

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
# F405 defined from star imports
1919

2020
# Rules that we'd like to enable in the future:
21-
# Y034 Detect common errors where certain methods are annotated as having a fixed
22-
# return type, despite returning self at runtime (temporarily disabled for
23-
# typing.pyi, enabled elsewhere).
2421
# Y037 Use PEP 604 syntax instead of `typing.Union` and `typing.Optional`.
2522
# Currently can't be enabled due to a few lingering bugs in mypy regarding
2623
# PEP 604 type aliases (see #4819).
@@ -33,6 +30,6 @@ per-file-ignores =
3330
# Unfortunately, flake8 does not allow to "noqa" just a specific error inside the file itself.
3431
# https://github.com/PyCQA/flake8/issues/1079
3532
# F811 redefinition of unused '...'
36-
stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y034, Y037
33+
stdlib/typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F811, F822, Y037
3734

3835
exclude = .venv*,.git,*_pb2.pyi

stdlib/typing.pyi

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import _typeshed
12
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
23
import sys
3-
from _typeshed import IdentityFunction, Incomplete, Self as TypeshedSelf, SupportsKeysAndGetItem
4+
from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem
45
from abc import ABCMeta, abstractmethod
56
from contextlib import AbstractAsyncContextManager, AbstractContextManager
67
from re import Match as Match, Pattern as Pattern
@@ -496,7 +497,7 @@ class MutableSequence(Sequence[_T], Generic[_T]):
496497
def reverse(self) -> None: ...
497498
def pop(self, index: int = ...) -> _T: ...
498499
def remove(self, value: _T) -> None: ...
499-
def __iadd__(self: TypeshedSelf, values: Iterable[_T]) -> TypeshedSelf: ...
500+
def __iadd__(self: _typeshed.Self, values: Iterable[_T]) -> _typeshed.Self: ...
500501

501502
class AbstractSet(Collection[_T_co], Generic[_T_co]):
502503
@abstractmethod
@@ -522,10 +523,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
522523
def clear(self) -> None: ...
523524
def pop(self) -> _T: ...
524525
def remove(self, value: _T) -> None: ...
525-
def __ior__(self: TypeshedSelf, it: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc]
526-
def __iand__(self: TypeshedSelf, it: AbstractSet[Any]) -> TypeshedSelf: ...
527-
def __ixor__(self: TypeshedSelf, it: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc]
528-
def __isub__(self: TypeshedSelf, it: AbstractSet[Any]) -> TypeshedSelf: ...
526+
def __ior__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc]
527+
def __iand__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ...
528+
def __ixor__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc]
529+
def __isub__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ...
529530

530531
class MappingView(Sized):
531532
def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented
@@ -778,7 +779,7 @@ class NamedTuple(tuple[Any, ...]):
778779
else:
779780
def _asdict(self) -> collections.OrderedDict[str, Any]: ...
780781

781-
def _replace(self: TypeshedSelf, **kwargs: Any) -> TypeshedSelf: ...
782+
def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ...
782783

783784
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
784785
# 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):
788789
if sys.version_info >= (3, 9):
789790
__required_keys__: ClassVar[frozenset[str]]
790791
__optional_keys__: ClassVar[frozenset[str]]
791-
def copy(self: TypeshedSelf) -> TypeshedSelf: ...
792+
def copy(self: _typeshed.Self) -> _typeshed.Self: ...
792793
# Using NoReturn so that only calls using mypy plugin hook that specialize the signature
793794
# can go through.
794795
def setdefault(self, k: NoReturn, default: object) -> object: ...
@@ -800,8 +801,8 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
800801
def keys(self) -> KeysView[str]: ...
801802
def values(self) -> ValuesView[object]: ...
802803
if sys.version_info >= (3, 9):
803-
def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ...
804-
def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ...
804+
def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
805+
def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ...
805806

806807
@_final
807808
class ForwardRef:

0 commit comments

Comments
 (0)