Skip to content

Do not follow imports from stubs with --follow-imports=skip #3738

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

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,12 +1377,9 @@ def __init__(self,
# - skip -> don't analyze, make the type Any
follow_imports = self.options.follow_imports
if (follow_imports != 'normal'
and not root_source # Honor top-level modules
and path.endswith('.py') # Stubs are always normal
and id != 'builtins' # Builtins is always normal
and not (caller_state and
caller_state.tree and
caller_state.tree.is_stub)):
and not root_source # Honor top-level modules
and path.endswith('.py') # Stubs are always normal
and id != 'builtins'): # Builtins is always normal
if follow_imports == 'silent':
# Still import it, but silence non-blocker errors.
manager.log("Silencing %s (%s)" % (path, id))
Expand Down
17 changes: 11 additions & 6 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -955,19 +955,24 @@ tmp/foo/bar.py: note: (Using --follow-imports=error, submodule passed on command
# cmd: mypy -m main
# flags: --follow-imports=skip
[file main.py]
from stub import x # Permitted
from other import y # Disallowed
x + '' # Error here
y + '' # But not here
from stub import x, z # Followed
from other import y # Not followed
x + '' # No error here
y + '' # No error here
z + '' # Error here
[file stub.pyi]
from non_stub import x
from non_stub import x # this import is not followed

z = 42
[file non_stub.py]
x = 42

x + '' # no error because file is not analyzed
[file other.py]
y = 42
[builtins fixtures/module.pyi]
[out]
tmp/main.py:3: error: Unsupported left operand type for + ("int")
tmp/main.py:5: error: Unsupported left operand type for + ("int")

[case testSilentSubmoduleImport]
# cmd: mypy -m foo
Expand Down