Skip to content

Write test to make sure imports stay silenced when using silent_imports + incremental. #2036

Open
@Michael0x2a

Description

@Michael0x2a

I recently ran into a bug related to silenced modules sometimes being un-silenced and re-checked (?) when combining silent_imports and incremental mode and forcing an SCC to be rechecked (using commit fc03d438d61adf95e6a1aed6fb9fbdf986a90602, the latest version on master as of time of writing).

While I was able to find a fix and will be submitting a pull request shortly, I wasn't able to write a test case. It would be nice to fix that, though it's challenging to do so for a few reasons. More details:


This bug manifests after you...

  1. Make mypy run with silent_imports and incremental mode enabled with a cold cache.
  2. Re-run mypy to establish a baseline for what running mypy on a fully fresh cache should be. On large code-bases, this step should finish substantially faster then step 1.
  3. Make a harmless change to some file which happens to be importing some files not provided on the command line (eg are not being typechecked). This file may need to be a part of some odd import cycle shenanigans.
  4. Re-run mypy.
  5. Re-run mypy again.

The expected behavior is that on step 5, mypy should take about the same amount of time to complete as on step 2, since there was no change after step 4 finished. However, the actual behavior is that step 5 will take about the same amount of time to run as step 4. After examining the logs, it seems the reason why this is the case is because in step 4, mypy is treating the previously silenced imports from the modified file as unsilenced, which causes them to be rechecked.

Unfortunately, I wasn't able to provide a test case because this problem seems to manifest mainly in larger code bases (with import cycles?) that are hard to simplify and after running incremental mode at least 3 times -- mypy's test suite can currently only run incremental two times.

While I was able to reliably repro the issue against the large code-base and will be submitting a pull request with a fix momentarily, it would be nice if it were possible to add an actual test case for this bug.

I'll try and working on adding a test case for this (probably after overhauling parts of the test framework), but I wanted to file an issue here in case this ends up dropping off my todo list.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions