-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Mypy mistakes instance attrs for class attrs? #15786
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
Comments
I think this is a duplicate of #240. |
Indeed |
FWIW, here is a description of how I addressed this problem in pyright. |
I'm far from an expert on this topic, but this issue (is about reading instance attributes as class attributes) does seem distinct from #240 (about writing them). (This issue is, however, a duplicate of #240 (comment), #15307, #1097 and others). The important difference between #240 and this issue, AIUI, is that the snippet in #240 doesn't raise an foo2 = Foo2(1)
foo2.baz # AttributeError: type object 'Foo2' has no attribute 'baz' It sounds like there are deep-seated reasons why this error is hard to catch statically, but python does indeed consider it an error. |
Bug Report
Consider the following class definition:
Mypy (1.4.1) correctly notices that
baz
is not defined. However, if we amend the class definition slightly by addingbaz
as an instance attr like so:now mypy doesn't spot the error anymore: it seems to be confused about whether
baz
is an instance or a class attr.To Reproduce
Please see playground gist here.
Expected Behavior
I would expect mypy to raise an [attr-defined] error for
Foo2
just as forFoo1
.Actual Behavior
[But mypy finds nothing for Foo2.]
Your Environment
mypy.ini
(and other config files): NAThanks!
The text was updated successfully, but these errors were encountered: