Skip to content
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

Bug: Imports do not seems to be handled correctly in 0.720 #7247

Closed
futursolo opened this issue Jul 20, 2019 · 5 comments
Closed

Bug: Imports do not seems to be handled correctly in 0.720 #7247

futursolo opened this issue Jul 20, 2019 · 5 comments

Comments

@futursolo
Copy link

I recently bumped my Mypy version from 0.701 to 0.720. It seems like Mypy's starting to process imported modules residing in the same directory as the one that's being checked. But it does not handle them correctly.

Environment:

macOS 10.14.5
Python 3.7.4
Mypy 0.720/0.701

Directory Structure:

|
|-- mod_a
|  |-- __init__.py
|
|-- mod_b
   |-- __init__.py
   |-- b.py

Content of mod_a/__init__.py:

import mod_b

class A(mod_b.B):
    pass

Content of mod_b/__init__.py:

from .b import B

Content of mod_b/b.py:

class B:
    pass

Command:

mypy --python-version 3.7 \
    --strict --show-traceback \
    --ignore-missing-imports \
    --show-error-context \
    -p mod_a

Error message in 0.720(no error in 0.701):

mod_a/__init__.py:4: error: Name 'mod_b.B' is not defined
mod_a/__init__.py: note: In class "A":
mod_a/__init__.py:4: error: Class cannot subclass 'B' (has type 'Any')
@JelleZijlstra
Copy link
Member

This is the expected behavior of the new --no-implicit-reexport flag, which is included in --strict. To make your code pass, use from .b import B as B in mod_b/__init__.py.

This is documented in https://mypy.readthedocs.io/en/latest/command_line.html#miscellaneous-strictness-flags.

@futursolo
Copy link
Author

Is there any chance we can make the error message clearer?

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 22, 2019

Yes, the error message should be clearer. Created #7251 to track this.

@futursolo
Copy link
Author

Also, upon further testing, --no-implicit-reexport does not seem to respect __all__either. Shouldn't variable names listed in __all__ also be considered as exported names?

@JelleZijlstra
Copy link
Member

That's being fixed in #7099.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants