Skip to content

mypy should not follow imports from stubs with --follow-imports=skip #3727

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
ilinum opened this issue Jul 17, 2017 · 1 comment
Closed

mypy should not follow imports from stubs with --follow-imports=skip #3727

ilinum opened this issue Jul 17, 2017 · 1 comment

Comments

@ilinum
Copy link
Collaborator

ilinum commented Jul 17, 2017

Currently, even with --follow-imports=skip imports from stub files are still followed. This means that if stub imports an unanalyzed module, the previously unanalyzed module is actually typechecked.

Consider the following example:

# main.py
from stub import x
# stub.pyi
from unanalyzed import x
# unanalyzed.py
x: int = 42

x + ''  # error is reported here but it shouldn't be because this file is unanalyzed

Currently, if you run mypy the following happens:

$ mypy main.py --follow-imports=skip
unanalyzed.py:4: error: Unsupported operand types for + ("int" and "str")

I think we should treat imports from stub and non-stub files the same way. Following imports from stubs in silent mode was implemented #1372.

Discovered this bug when investigating an error in Dropbox internal codebases.

@gvanrossum
Copy link
Member

Hm, reading through the original discussion in #1364 and #1372 I agree that this is an iffy feature and I'm fine with rolling it back. I don't think this was ever documented -- I don't even recall being aware of this corner case when I refactored --silent/-s into --follow-imports=<enum> and --ignore-missing-imports.

ilinum added a commit to ilinum/mypy that referenced this issue Jul 19, 2017
If such imports are followed, previously unanalyzed modules can become analyzed.

Fixes python#3727
ddfisher pushed a commit that referenced this issue Jul 21, 2017
If such imports are followed, unanalyzed modules can become analyzed when not intended.

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

No branches or pull requests

2 participants