From 0cc304157c97cec0256de688748fa929ddc7bf06 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Sat, 19 Feb 2022 19:37:23 -0800 Subject: [PATCH] typing: don't accidentally use typing.Self We can switch to it when all type checkers have support --- stdlib/typing.pyi | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 17062f1db3e2..202d4f287c43 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -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 @@ -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 @@ -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 @@ -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: ... @@ -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: ...