-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Class level __getattr__ causes error: __getattr__ is not valid at the module level outside a stub file #4069
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
Filed here: python/mypy#4069 We should go back to tracking the latest mypy releases as soon as possible.
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 |
Do you have a smaller repro yet?
|
@ethanhs Your diagnosis seems right. Here is a simple repro: class C:
def __getattr__(self, attr: str) -> int:
x: F
return x.f
class F:
def __init__(self, f: int) -> None:
self.f = f |
A related bug: from typing import TypeVar
T = TypeVar('T', bound=C)
class C:
def m(self: T) -> T:
class Inner:
x: F
f = x.f
return self
class F:
def __init__(self, f: int) -> None:
self.f = f results in a funny error:
|
OK, here is the PR #4073. |
Fixes #4069 This pushes the correct enclosing class while deferring a method instead of just the top class.
Confirmed fixed in mypy-0.540. Thanks for the quick response! |
Our bug (python/mypy#4069) was fixed in the mypy-0.540 release.
After updating to mypy 0.530, I am getting an error on a
__getattr__()
method defined on a class:I don't have any module level
__getattr__()
functions.This didn't reproduce with a smaller test case, but you can check out the Cretonne repo to reproduce.
The text was updated successfully, but these errors were encountered: