Skip to content

typing: don't accidentally use typing.Self #7318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
import sys
from _typeshed import Self, SupportsKeysAndGetItem
from _typeshed import Self as TypeshedSelf, SupportsKeysAndGetItem
from abc import ABCMeta, abstractmethod
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final
Expand Down Expand Up @@ -372,7 +372,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: Self, x: Iterable[_T]) -> Self: ...
def __iadd__(self: TypeshedSelf, x: Iterable[_T]) -> TypeshedSelf: ...

class AbstractSet(Collection[_T_co], Generic[_T_co]):
@abstractmethod
Expand All @@ -398,10 +398,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
def clear(self) -> None: ...
def pop(self) -> _T: ...
def remove(self, value: _T) -> None: ...
def __ior__(self: Self, s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc]
def __iand__(self: Self, s: AbstractSet[Any]) -> Self: ...
def __ixor__(self: Self, s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc]
def __isub__(self: Self, s: AbstractSet[Any]) -> Self: ...
def __ior__(self: TypeshedSelf, s: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc]
def __iand__(self: TypeshedSelf, s: AbstractSet[Any]) -> TypeshedSelf: ...
def __ixor__(self: TypeshedSelf, s: AbstractSet[_T]) -> TypeshedSelf: ... # type: ignore[override,misc]
def __isub__(self: TypeshedSelf, s: AbstractSet[Any]) -> TypeshedSelf: ...

class MappingView(Sized):
def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented
Expand Down Expand Up @@ -733,11 +733,11 @@ class NamedTuple(tuple[Any, ...]):
else:
def _asdict(self) -> collections.OrderedDict[str, Any]: ...

def _replace(self: Self, **kwargs: Any) -> Self: ...
def _replace(self: TypeshedSelf, **kwargs: Any) -> TypeshedSelf: ...

# Internal mypy fallback type for all typed dicts (does not exist at runtime)
class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def copy(self: Self) -> Self: ...
def copy(self: TypeshedSelf) -> TypeshedSelf: ...
# 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: ...
Expand All @@ -748,8 +748,8 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta):
def items(self) -> ItemsView[str, object]: ...
def keys(self) -> KeysView[str]: ...
def values(self) -> ValuesView[object]: ...
def __or__(self: Self, __value: Self) -> Self: ...
def __ior__(self: Self, __value: Self) -> Self: ...
def __or__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ...
def __ior__(self: TypeshedSelf, __value: TypeshedSelf) -> TypeshedSelf: ...

# This itself is only available during type checking
def type_check_only(func_or_cls: _F) -> _F: ...
Expand Down