I would like to draft a PEP for a typing.Self class which would perform similarly to rust's Self keyword in function annotations.
Examples
```python
from typing import TypeVar
F = TypeVar("F", bound="Foo")
class Foo:
def parse(self: F, data: bytes) -> F:
...
return self
```
vs
```python
from typing import Self
class Foo:
def parse(self, data: bytes) -> Self:
...
return self
```
Another example of where this could be useful is classmethods:
```python
class Foo:
@classmethod
def bar(cls: type[F], *args: Any, **kwargs: Any) -> F:
return cls()
```
vs
```python
class Foo:
@classmethod
def bar(cls, *args: Any, **kwargs: Any) -> Self:
return cls()
```
Implementation wise it would be a copy of NoReturn, i.e. not subscriptable, a _SpecialForm and should only be valid as a return type.
I haven't seen any discussion of the idea on the mailing list, so I wanted to run it by everyone.
Thanks,
James.
_______________________________________________