-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self
type support
#1283
Comments
Generally, we add support for new typing features a few months after adding support for the corresponding Python version. Since |
* Adds (very) partial support for typing.Self. * Adds a missing __buffer__ method to bytes. For #1283. PiperOrigin-RevId: 540159072
* Supports Self in a container annotation. * Supports Self in a function parameter annotation. * Supports Self in a nested class. For #1283. PiperOrigin-RevId: 540443019
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
|
I added some support specifically for |
Got it, thanks! |
* Turns typing.Self into a TypeVar and annotates `self` with it when we detect that a method signature uses typing.Self. * Renames some variables, attributes, and methods related to `self` annotations because the previous names were confusing me. * Fixes a bug in overlay_utils.not_supported_yet that prevented it from converting an alias to a TypeVar to an abstract value. * Fixes a bug in convert.py that caused it to report spurious recursion errors if conversion to an abstract value raises NotImplementedError. For #1283. PiperOrigin-RevId: 574945687
For #1283. PiperOrigin-RevId: 574971273
* Adds `bound=<class>` to Self occurrences. * Prints typing.Self as `from typing import Self` in pyi files rather than defining a new TypeVar named Self. For #1283. PiperOrigin-RevId: 575328499
…yet error. All that's left to implement is use of Self in attribute annotations. For #1283. PiperOrigin-RevId: 575492431
For #1283. PiperOrigin-RevId: 576676199
Next week's pytype release will have Self support. |
@rchen152 - I'm getting class A:
def a(self, **kwargs) -> "Self":
return self.__class__(**(self.__dict__ | kwargs))
class B(A):
@overrides.override
def a(self, **kwargs) -> "Self":
self.super().a(**(dict(option="default") | kwargs)) Is this considered an inappropriate use of |
It would be nice to support the
Self
type in the future. Is there a plan in this direction?PEP 673
Code example
foo.py
:The text was updated successfully, but these errors were encountered: