mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Remove more explicit Self
annotations
This commit is contained in:
parent
53404d340d
commit
b9a57d3eca
2 changed files with 6 additions and 10 deletions
|
@ -324,8 +324,7 @@ a covariant generic, this is equivalent to using the upper bound of the type par
|
||||||
from typing import Self
|
from typing import Self
|
||||||
|
|
||||||
class Covariant[T]:
|
class Covariant[T]:
|
||||||
# TODO: remove the explicit `Self` annotation, once we support the implicit type of `self`
|
def get(self) -> T:
|
||||||
def get(self: Self) -> T:
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _(x: object):
|
def _(x: object):
|
||||||
|
@ -338,8 +337,7 @@ Similarly, contravariant type parameters use their lower bound of `Never`:
|
||||||
|
|
||||||
```py
|
```py
|
||||||
class Contravariant[T]:
|
class Contravariant[T]:
|
||||||
# TODO: remove the explicit `Self` annotation, once we support the implicit type of `self`
|
def push(self, x: T) -> None: ...
|
||||||
def push(self: Self, x: T) -> None: ...
|
|
||||||
|
|
||||||
def _(x: object):
|
def _(x: object):
|
||||||
if isinstance(x, Contravariant):
|
if isinstance(x, Contravariant):
|
||||||
|
@ -354,10 +352,8 @@ the type system, so we represent it with the internal `Top[]` special form.
|
||||||
|
|
||||||
```py
|
```py
|
||||||
class Invariant[T]:
|
class Invariant[T]:
|
||||||
# TODO: remove the explicit `Self` annotation, once we support the implicit type of `self`
|
def push(self, x: T) -> None: ...
|
||||||
def push(self: Self, x: T) -> None: ...
|
def get(self) -> T:
|
||||||
# TODO: remove the explicit `Self` annotation, once we support the implicit type of `self`
|
|
||||||
def get(self: Self) -> T:
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _(x: object):
|
def _(x: object):
|
||||||
|
|
|
@ -103,6 +103,6 @@ class NamedTupleLike(Protocol):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _make(cls: type[Self], iterable: Iterable[Any]) -> Self: ...
|
def _make(cls: type[Self], iterable: Iterable[Any]) -> Self: ...
|
||||||
def _asdict(self, /) -> dict[str, Any]: ...
|
def _asdict(self, /) -> dict[str, Any]: ...
|
||||||
def _replace(self: Self, /, **kwargs) -> Self: ...
|
def _replace(self, /, **kwargs) -> Self: ...
|
||||||
if sys.version_info >= (3, 13):
|
if sys.version_info >= (3, 13):
|
||||||
def __replace__(self: Self, **kwargs) -> Self: ...
|
def __replace__(self, **kwargs) -> Self: ...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue