-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Automatically use Self
type even if it doesn't appear in method annotation
#14075
Comments
For what it's worth, pyre and pyright both adopted the former approach. (PEP 673, which introduces the Pyright has had support for |
I think PEP 484 has not expected to ever be a |
I just closed #14708 as a duplicate of this issue |
This is a follow up for #14041
This example gives an error:
Although it is unfortunate, technically this is required by PEP 484, that says that if no annotation is given,
self
has a type of current class (note also we can't bind self type forself.x
expression giving it typeC
, as this will open another unsafety). This can be avoided by using e.g.self: Self
(or generallySelf
type anywhere in the signature).It looks like there can be only two solutions:
Self
type forself
. This will cause a big performance penalty and may be surprising for users who are not familiar withSelf
(if they usereveal_type(self)
).Self
where otherwise we will have this problem. For example, inferSelf
if an attribute with type containingSelf
is used anywhere in a method.I am leaning towards the latter, but didn't want to do this until we get some more experience.
The text was updated successfully, but these errors were encountered: