-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
More crashes in class scoped imports #12197
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
Okay, so while #12023 fixed a bunch of crashes, it also resulted in some new crashes. It also looks like there's some kind of caching bug at play, so make sure to use
It looks like the "copy" is a little strong, since mypy now looks for typevars (and presumably the overload symbol and other decorators) in the file in which things were imported. But we do need at least enough of a copy of the symbol that we can associate set the info attribute on it. If we want to continue barrelling down this path, we need to stub out at least the body of the constructed node. Jukka had suggested making this a blocking error. I'd prefer not to do that, because a blocking error is only slightly better than a crash and this would prevent me from using mypy on a codebase at work. Maybe we just issue a non-blocking error and create an |
import *
in class bodies should be disallowed
I realise I sort of hijacked this issue. Opened #12198 for the low-pri issue. |
Do you know what the exact conditions are under which it now crashes? Is it importing a function from a stub? |
Multiple things are bad:
It's basically copy-pasting the definition of the function into the class, so then mypy can't look up the typevar and doesn't know what overload is. |
More context in python#12197 This essentially walks back changes in python#12023 that apply to function-like things that are imported in class-scope. We just issue a (non-blocking) error and mark the type as Any. Inference for variables still works fine; I'm yet to think of any problems that could cause. A full fix seems quite difficult, but this is better than both a crash and a blocking error.
Fixes #12197 This essentially walks back changes in #12023 that apply to function-like things that are imported in class-scope. We just issue a (non-blocking) error and mark the type as Any. Inference for variables still works fine; I'm yet to think of any problems that could cause. A full fix seems quite difficult, but this is better than both a crash and a blocking error.
In Python 3 (but not Python 2), it is illegal to do
import *
in class body, but mypy allows it.It also crashes if you do
class X: from os import *
:The text was updated successfully, but these errors were encountered: