Skip to content

Module Aliases for PEP 561 not working #5331

Closed

Description

@alanhdu

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'

Activity

  1. alanhdu commented on Jul 7, 2018

    @alanhdu
    Author

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

  2. emmatyping commented on Jul 8, 2018

    @emmatyping
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions