-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Change in behavior regarding __getattr__
and @no_type_check
#13319
Comments
A workaround is to use:
I'm not sure that |
I don't think |
Okay yeah, I'm going to close this as won't fix then. For the record,
This makes sense, previously mypy struggled to understand decorators on |
Behaviour changed in recent releases: python/mypy#13319
ExtendedLogger mainly exists to make typing happy. It's a subclass of logging.Logger (so typing understands it has all the methods of that class). Additionally, it has a few extended methods that we add. This is hacked together by overwriting __getattribute__() and delegating most calls to the wrapped logger. This works, except that defining __getattribute__() in a class makes mypy think that the object supports any kind of object. So `logger.bogus()` is not flagged as an error and misses a linter error. Work around that. See-also: python/mypy#13319 (comment)
ExtendedLogger mainly exists to make typing happy. It's a subclass of logging.Logger (so typing understands it has all the methods of that class). Additionally, it has a few extended methods that we add. This is hacked together by overwriting __getattribute__() and delegating most calls to the wrapped logger. This works, except that defining __getattribute__() in a class makes mypy think that the object supports any kind of object. So `logger.bogus()` is not flagged as an error and misses a linter error. Work around that. See-also: python/mypy#13319 (comment)
ExtendedLogger mainly exists to make typing happy. It's a subclass of logging.Logger (so typing understands it has all the methods of that class). Additionally, it has a few extended methods that we add. This is hacked together by overwriting __getattribute__() and delegating most calls to the wrapped logger. This works, except that defining __getattribute__() in a class makes mypy think that the object supports any kind of object. So `logger.bogus()` is not flagged as an error and misses a linter error. Work around that. See-also: python/mypy#13319 (comment)
ExtendedLogger mainly exists to make typing happy. It's a subclass of logging.Logger (so typing understands it has all the methods of that class). Additionally, it has a few extended methods that we add. This is hacked together by overwriting __getattribute__() and delegating most calls to the wrapped logger. This works, except that defining __getattribute__() in a class makes mypy think that the object supports any kind of object. So `logger.bogus()` is not flagged as an error and misses a linter error. Work around that. See-also: python/mypy#13319 (comment)
Bug Report
In #6251 it was recommended to use
@no_type_check
on__getattr__
if you wanted errors to still be raised for missing attributes. However this appears to no longer work since v0.930To Reproduce
Expected Behavior
Following the discussion on #6251, I expected that adding a
@no_type_check
decorator would restore errors on missing attributes. I see this behavior on several versions <= 0.921When running
mypy test.py
on version 0.921 I get the expected outputActual Behavior
When running on versions 0.930-0.971 I do not see the (expected) first error indicating the missing attribute,
Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: