`Self` type support
It would be nice to support the Self type in the future. Is there a plan in this direction?
Code example
foo.py:
from typing_extensions import Self
class A:
def func(self) -> Self:
return self
$ pytype foo.py
[...]
File "/Users/quentingallouedec/foo.py", line 1, in <module>: typing_extensions.Self not supported yet [not-supported-yet]
Generally, we add support for new typing features a few months after adding support for the corresponding Python version. Since Self is in 3.11, which we haven't started seriously looking at yet, it'll probably be sometime next year before we support it.
Hi @rchen152! What is the status of Self type now? It looks like you added support for even some complex cases, but when I try the example from OP with pytype 2023.06.16, I still get
File "/home/eltoder/dev/scratch/self_type.py", line 1, in <module>: typing.Self not supported yet [not-supported-yet]
File "/home/eltoder/dev/scratch/self_type.py", line 5, in func: bad return type [bad-return-type]
Expected: Self
Actually returned: A
I added some support specifically for Self type in .pyi (stub) files, to help with updating the typeshed version that pytype uses. From a pytype user perspective, what I'm adding now probably isn't particularly useful, since it doesn't allow you to use Self in .py source files.
Got it, thanks!
Next week's pytype release will have Self support.