diff --git a/mypy/build.py b/mypy/build.py index 21a5559b329a..8d5db0bab8df 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -4769,13 +4769,13 @@ def process_stale_scc(graph: Graph, ascc: SCC, manager: BuildManager) -> None: t2 = time.time() stale = scc + # Parse before verify_dependencies so that inline config comments + # (e.g. "# mypy: disable-error-code") are applied to options. + manager.parse_all([graph[id] for id in stale], post_parse=False) for id in stale: # Re-generate import errors in case this module was loaded from the cache. if graph[id].meta: graph[id].verify_dependencies(suppressed_only=True) - # We may already have parsed the modules, or not. - # If the former, parse_file() is a no-op. - manager.parse_all([graph[id] for id in stale], post_parse=False) if "typing" in scc: # For historical reasons we need to manually add typing aliases # for built-in generic collections, see docstring of diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 6911a350376f..db15b7341910 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -7995,3 +7995,19 @@ import mod [out2] main:2: error: Cannot find implementation or library stub for module named "mod" main:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports + +[case testIncrementalFileConfigCommentsStale] +-- When a dependency changes, the importing module becomes stale and is +-- reprocessed via process_stale_scc. As inline config comments are not cached +-- (by design), moving the order of processing the stale SCC can accidentally +-- break file config comments on subsequent runs. +# mypy: disable-error-code="import-not-found" +import nonexistent +import b +[file b.py] +x = 1 +[file b.py.2] +x = "hello" +[builtins fixtures/module.pyi] +[stale b] +[rechecked b]