You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Class level __getattr__ causes error: __getattr__ is not valid at the module level outside a stub file #4069
Confirmed on master, I am stepping through now. I appears the issue only occurs in the second pass of the checker (the class is added to the scope stack in the first pass, but not in the second).
It appears that when we defer functions to the second pass, we try to put the class context information. However, the function node is not removed on L261, so the class is not resolved, and that returns None. This later causes issues when we try to append the class context, but cannot, so the __getattr__ method appears to be in the file context (this occurs in check_second_pass). The __getattr__ checking for module levels if the first thing that relied on the size of the scope being 1 (module level), so it exposed this issue.
Activity
Roll back to mypy 0.521 to avoid a bug in 0.530.
emmatyping commentedon Oct 6, 2017
Confirmed on master, I am stepping through now. I appears the issue only occurs in the second pass of the checker (the class is added to the scope stack in the first pass, but not in the second).
emmatyping commentedon Oct 6, 2017
It appears that when we defer functions to the second pass, we try to put the class context information. However, the function
nodeis not removed on L261, so the class is not resolved, and that returnsNone. This later causes issues when we try to append the class context, but cannot, so the__getattr__method appears to be in the file context (this occurs incheck_second_pass). The__getattr__checking for module levels if the first thing that relied on the size of the scope being 1 (module level), so it exposed this issue.gvanrossum commentedon Oct 6, 2017
ilevkivskyi commentedon Oct 8, 2017
@ethanhs Your diagnosis seems right. Here is a simple repro:
ilevkivskyi commentedon Oct 8, 2017
A related bug:
results in a funny error:
ilevkivskyi commentedon Oct 8, 2017
OK, here is the PR #4073.
Push correct enclosing class while deferring a method (#4073)
stoklund commentedon Oct 21, 2017
Confirmed fixed in mypy-0.540. Thanks for the quick response!
Go back to tracking the latest mypy release.