Skip to content

Commit

Permalink
Fix re-added file with errors in mypy daemon (#15440)
Browse files Browse the repository at this point in the history
Fixes #5343
Fixes #12249

This can potentially slow down runs in situations where multiple
unchanged files are re-added to source list. Potentially, we can track
whether modules had errors permanently (not just from previous run), and
then only re-check those unchanged re-added files that had errors
before. I am not sure if this is important.
  • Loading branch information
ilevkivskyi authored Jun 15, 2023
1 parent bf92309 commit ceb4d7f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,21 @@ def _find_changed(
assert path
removed.append((source.module, path))

# Always add modules that were (re-)added, since they may be detected as not changed by
# fswatcher (if they were actually not changed), but they may still need to be checked
# in case they had errors before they were deleted from sources on previous runs.
previous_modules = {source.module for source in self.previous_sources}
changed_set = set(changed)
changed.extend(
[
(source.module, source.path)
for source in sources
if source.path
and source.module not in previous_modules
and (source.module, source.path) not in changed_set
]
)

# Find anything that has had its module path change because of added or removed __init__s
last = {s.path: s.module for s in self.previous_sources}
for s in sources:
Expand Down
22 changes: 22 additions & 0 deletions test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ Daemon started
\[mypy]
files = ./foo.py

[case testDaemonRunMultipleStrict]
$ dmypy run -- foo.py --strict --follow-imports=error
Daemon started
foo.py:1: error: Function is missing a return type annotation
foo.py:1: note: Use "-> None" if function does not return a value
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
$ dmypy run -- bar.py --strict --follow-imports=error
bar.py:1: error: Function is missing a return type annotation
bar.py:1: note: Use "-> None" if function does not return a value
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
$ dmypy run -- foo.py --strict --follow-imports=error
foo.py:1: error: Function is missing a return type annotation
foo.py:1: note: Use "-> None" if function does not return a value
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
[file foo.py]
def f(): pass
[file bar.py]
def f(): pass

[case testDaemonRunRestart]
$ dmypy run -- foo.py --follow-imports=error
Daemon started
Expand Down
21 changes: 21 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -10340,3 +10340,24 @@ reveal_type(x)
[out]
==
a.py:3: note: Revealed type is "Union[def (x: builtins.int) -> builtins.int, def (*x: builtins.int) -> builtins.int]"

[case testErrorInReAddedModule]
# flags: --disallow-untyped-defs --follow-imports=error
# cmd: mypy a.py
# cmd2: mypy b.py
# cmd3: mypy a.py

[file a.py]
def f(): pass
[file b.py]
def f(): pass
[file unrelated.txt.3]
[out]
a.py:1: error: Function is missing a return type annotation
a.py:1: note: Use "-> None" if function does not return a value
==
b.py:1: error: Function is missing a return type annotation
b.py:1: note: Use "-> None" if function does not return a value
==
a.py:1: error: Function is missing a return type annotation
a.py:1: note: Use "-> None" if function does not return a value

0 comments on commit ceb4d7f

Please sign in to comment.