You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`.fromtypingimportTypeVarSelf=TypeVar("Self", bound="A")
classA:
deffoo(self: Self) ->Self:
returnself
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.
Are you using mypy master? Mypy doesn't support typing.Self yet in any released version, so if you're using mypy 0.991 or older, that's why you're seeing the error. It will support typing.Self in the way you'd like it to in the next release (mypy 1.0).
Thanks, I was testing in the linked mypy Playground. Checking back on it with the other versions, you're right in that the master branch works as expected, while every other version failed.
Bug Report
Using
self: Self
orcls: type[Self]
results in an error.To Reproduce
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.Actual Behavior
Requires
self: Self
to be changed to justself
everywhere.Your Environment
mypy Playground
The text was updated successfully, but these errors were encountered: