Skip to content

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

Closed
@ilinum

Description

@ilinum

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions