From b9a57d3eca6d5b59b542d887bb3bc1a9f16f6434 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 25 Sep 2025 13:42:44 +0200 Subject: [PATCH] Remove more explicit `Self` annotations --- .../resources/mdtest/narrow/isinstance.md | 12 ++++-------- crates/ty_vendored/ty_extensions/ty_extensions.pyi | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md b/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md index 486c354c24..60ec2fa844 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/isinstance.md @@ -324,8 +324,7 @@ a covariant generic, this is equivalent to using the upper bound of the type par from typing import Self class Covariant[T]: - # TODO: remove the explicit `Self` annotation, once we support the implicit type of `self` - def get(self: Self) -> T: + def get(self) -> T: raise NotImplementedError def _(x: object): @@ -338,8 +337,7 @@ Similarly, contravariant type parameters use their lower bound of `Never`: ```py class Contravariant[T]: - # TODO: remove the explicit `Self` annotation, once we support the implicit type of `self` - def push(self: Self, x: T) -> None: ... + def push(self, x: T) -> None: ... def _(x: object): if isinstance(x, Contravariant): @@ -354,10 +352,8 @@ the type system, so we represent it with the internal `Top[]` special form. ```py class Invariant[T]: - # TODO: remove the explicit `Self` annotation, once we support the implicit type of `self` - def push(self: Self, x: T) -> None: ... - # TODO: remove the explicit `Self` annotation, once we support the implicit type of `self` - def get(self: Self) -> T: + def push(self, x: T) -> None: ... + def get(self) -> T: raise NotImplementedError def _(x: object): diff --git a/crates/ty_vendored/ty_extensions/ty_extensions.pyi b/crates/ty_vendored/ty_extensions/ty_extensions.pyi index ccaf90a06e..def2cd0963 100644 --- a/crates/ty_vendored/ty_extensions/ty_extensions.pyi +++ b/crates/ty_vendored/ty_extensions/ty_extensions.pyi @@ -103,6 +103,6 @@ class NamedTupleLike(Protocol): @classmethod def _make(cls: type[Self], iterable: Iterable[Any]) -> Self: ... def _asdict(self, /) -> dict[str, Any]: ... - def _replace(self: Self, /, **kwargs) -> Self: ... + def _replace(self, /, **kwargs) -> Self: ... if sys.version_info >= (3, 13): - def __replace__(self: Self, **kwargs) -> Self: ... + def __replace__(self, **kwargs) -> Self: ...