Closed as not planned
Description
Bug Report
Using self: Self
or cls: type[Self]
results in an error.
To Reproduce
from typing import Self
class A:
def foo(self: Self) -> Self:
return self
Expected Behavior
The behavior should be equivalent to the workaround explained in PEP 673 before we had typing.Self
. Users which previously used the old code would otherwise have to change all of the code which used the previous workaround to work with the new change or continue to use the old workaround.
# Should be a simple change to `from typing import Self`.
from typing import TypeVar
Self = TypeVar("Self", bound="A")
class A:
def foo(self: Self) -> Self:
return self
Actual Behavior
main.py:6: error: Variable "typing.Self" is not valid as a type [valid-type]
main.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Requires self: Self
to be changed to just self
everywhere.
Your Environment