Skip to content

--follow-imports=silent is not silent if imported file is in cache. #20508

Description

@sjoerdjob

Bug Report

When a file has been previously analyzed, and errors were found, and that result was cached,
(A clear and concise description of what the bug is.)

To Reproduce

Similar to

[case testIncrementalWithSilentImports]
, but with an extra cmd3/out3 equal to the first.

Create two files:

# a.py
import b

b.foo(1, 2)

and

# b.py
def foo(a: int, b: int) -> str:
    return a + b

Then, run the following three commands (in this order):

  1. mypy --follow-imports=silent a.py
  2. mypy --follow-imports=silent b.py
  3. mypy --follow-imports=silent a.py (same as first command)

(A more 'minimal' example would be to not run mypy --follow-imports=silent a.py first, which still exhibits the bug, but I think running 'a', 'b', 'a' more clearly shows the bug).

Expected Behavior*

Only run 2 (the one directly analyzing b.py) produces output.

# mypy --follow-imports=silent a.py
Success: no issues found in 1 source file
# mypy --follow-imports=silent b.py
b.py:2: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 1 source file)
# mypy --follow-imports=silent a.py
Success: no issues found in 1 source file

Actual Behavior

# mypy --follow-imports=silent a.py
Success: no issues found in 1 source file
# mypy --follow-imports=silent b.py
b.py:2: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 1 source file)
# mypy --follow-imports=silent a.py
b.py:2: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 1 source file)

Note how the third run (which uses --follow-imports=silent) is not silent about errors in not explicitly listed files, while the first was.

Your Environment

  • Mypy version used: 1.19.1 (but reproducible on master)
  • Mypy command-line flags: --follow-imports=silent
  • Mypy configuration options from mypy.ini (and other config files): None.
  • Python version used: 3.13.11

Activity

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions