Skip to content

mypy fails to recognise assignment as a form of module aliasing #1778

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

Closed
Diggsey opened this issue Jun 30, 2016 · 0 comments
Closed

mypy fails to recognise assignment as a form of module aliasing #1778

Diggsey opened this issue Jun 30, 2016 · 0 comments
Labels
bug mypy got something wrong priority-1-normal

Comments

@Diggsey
Copy link

Diggsey commented Jun 30, 2016

Example:

# a.pyi
class Foo:
    ...
# b.py
import a

a2 = a

x = a2.Foo  # error: module has no attribute Foo
@gvanrossum gvanrossum added the bug mypy got something wrong label Jul 7, 2016
@gvanrossum gvanrossum added this to the 0.5 milestone Jul 7, 2016
@gvanrossum gvanrossum removed this from the 0.5 milestone Mar 29, 2017
carljm added a commit to carljm/mypy that referenced this issue May 24, 2017
In semantic analysis, if we find a simple assignment statement where the rvalue
is a module, make the lvalue a direct alias to that same module.

Fixes python#1778.
carljm added a commit to carljm/mypy that referenced this issue May 24, 2017
In semantic analysis, if we find a simple assignment statement where the rvalue
is a module, make the lvalue a direct alias to that same module.

Fixes python#1778.
ilevkivskyi pushed a commit that referenced this issue Jun 3, 2017
* Detect and support module aliasing via assignment.

In semantic analysis, if we find a simple assignment statement where the rvalue
is a module, make the lvalue a direct alias to that same module.

Fixes #1778.

* Handle chained assignment and iterable unpacking assignment.

* Remove test case that was only for exploration, not intended for inclusion.

* Add some more tests for module assignment.

* Also add tests for access/assignment of nonexistent module attribute.

* Break down code and add comments for clarity; add test for mismatch lengths.

* Naming improvements.

* Support tracking module assignment in non-global scope.

* Add more tests for unpacking mismatch cases.

* Keep rvals always on the right.

* Don't use a form of unpacking that is Py35+ only.

* It's the zip that is problematic, not just the unpacking.

* Add tests for module assignment in class and local scopes.

* Simplify to single method.

* Go back to annotating genericpath as Any in stdlib-sample.

* Respect explicit type annotation and don't propagate module reference.

* Backtrack to simple ModuleType var in case of incompatible module aliasing.

* Remove stray pdb comment.

* Also handle reassignment of an original (non-alias) module reference.

* Simplify: fail on assignment of different modules to same variable without explicit annotation.

* Style and working tweaks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

No branches or pull requests

2 participants