Skip to content

Conditonally define module after initialization to None #1106

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

Open
JukkaL opened this issue Jan 8, 2016 · 1 comment
Open

Conditonally define module after initialization to None #1106

JukkaL opened this issue Jan 8, 2016 · 1 comment
Labels
false-positive mypy gave an error on correct code feature priority-1-normal

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 8, 2016

Mypy complains about this code, even though it's valid Python:

if x:
    m = None
else:
    import m

The most obvious way to fix this would be to add support for "module types" for specific modules. In the above example, m would be a variable with a partial None type initially. The import statement would switch the partial type to the type of module m.

(This is derived from discussion in #649.)

@JukkaL JukkaL added the feature label Jan 8, 2016
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jan 8, 2016

Module types would also make module aliases via assignment work:

import m
alias = m
alias.foo()  # Mypy currently complains about this

@ddfisher ddfisher added this to the 0.4.0 milestone Mar 2, 2016
@gvanrossum gvanrossum removed this from the 0.5 milestone Mar 29, 2017
@JukkaL JukkaL added the false-positive mypy gave an error on correct code label May 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive mypy gave an error on correct code feature priority-1-normal
Projects
None yet
Development

No branches or pull requests

3 participants