Skip to content

Module Aliases for PEP 561 not working #5331

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
alanhdu opened this issue Jul 7, 2018 · 2 comments
Closed

Module Aliases for PEP 561 not working #5331

alanhdu opened this issue Jul 7, 2018 · 2 comments
Labels
bug mypy got something wrong priority-0-high

Comments

@alanhdu
Copy link
Contributor

alanhdu commented Jul 7, 2018

Using the mypy's master branch (219fbf8) and pip installing https://github.com/numpy/numpy-stubs (a PEP 561 package), running mypy on the following code:

import numpy as np

def f(x: np.ndarray):
    reveal_type(x)

outputs:

test.py:4: error: Revealed type is 'Any'

But if I do:

from numpy import ndarray

def f(x: ndarray):
    reveal_type(x)

then I get the expected

test.py:4: error: Revealed type is 'numpy.ndarray'
@alanhdu
Copy link
Contributor Author

alanhdu commented Jul 7, 2018

Note that this example works perfectly fine with mypy 0.610. I ran a git bisect and believe that d91efd4 introduced the current behavior.

@emmatyping emmatyping added bug mypy got something wrong priority-0-high labels Jul 7, 2018
@emmatyping
Copy link
Member

Confirmed the bisect, and it is happening on master.

The issue is this part here: https://github.com/python/mypy/blob/master/mypy/semanal.py#L3081. It appears that adding the __getattr__ check is too earnest, it does not allow for re-binding that occurs on line 3098.

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-0-high
Projects
None yet
Development

No branches or pull requests

2 participants