-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Warn if instance atribute is defined outside of __init__ #10552
Comments
For what it's worth, I prototyped this feature in pyright after noticing this issue. We found that it was very noisy (hundreds or thousands of false positive errors in some representative code bases) and did little, if anything, to discover actual bugs. The largest source of errors was in unit tests, which typically have a method such as |
PyCharm silently ignores this error if name of the method is By the way, mypy generates an error if instance attribute is created outside of the class... |
I just ran into an issue because of a typo and was a bit surprised that Mypy didn't warn me.
It looks like the only static analyzer that catches this otherwise is Pylint. |
Feature
(Optionally?) generate error if the instance attribute is defined outside of
__init__
Pitch
Mypy does not generate any errors for the code below:
which fails with run time error, caused by the absence of the
abc
attribute definition in the__init__
method.Additionaly:
PyCharm and pylint generate error in the line 6.
The text was updated successfully, but these errors were encountered: