Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix re-added file with errors in mypy daemon #15440

Merged
merged 2 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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