Skip to content

Commit df1ccca

Browse files
committed
Fix dmypy suggest crash after flushed diagnostics
1 parent 0ff707d commit df1ccca

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

mypy/suggestions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def restore_after(self, module: str) -> Iterator[None]:
308308
try:
309309
yield
310310
finally:
311+
self.manager.errors.reset()
311312
self.reload(self.graph[module])
312313

313314
@contextmanager

mypy/test/testfinegrained.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import os
1818
import re
1919
import sys
20+
import tempfile
2021
import unittest
22+
from pathlib import Path
2123
from typing import Any
2224

2325
import pytest
@@ -376,6 +378,38 @@ def normalize_messages(messages: list[str]) -> list[str]:
376378

377379

378380
class TestMessageSorting(unittest.TestCase):
381+
def test_suggest_callsites_with_existing_messages(self) -> None:
382+
with tempfile.TemporaryDirectory() as tmp:
383+
tmp_path = Path(tmp)
384+
source_path = tmp_path / "main.py"
385+
source_path.write_text("reveal_type(1)\n", encoding="utf8")
386+
options = Options()
387+
options.follow_imports = "normal"
388+
options.use_builtins_fixtures = False
389+
options.error_summary = False
390+
server = Server(options, str(tmp_path / "dmypy.status"))
391+
392+
result = server.check(
393+
[BuildSource(str(source_path), "__main__", None)],
394+
export_types=False,
395+
is_tty=False,
396+
terminal_width=-1,
397+
)
398+
assert result["status"] == 0
399+
400+
response = server.cmd_suggest(
401+
"os.path.islink",
402+
json=False,
403+
no_any=False,
404+
no_errors=False,
405+
flex_any=None,
406+
use_fixme=None,
407+
callsites=True,
408+
max_guesses=None,
409+
)
410+
assert response.get("status") == 0
411+
assert "error" not in response
412+
379413
def test_simple_sorting(self) -> None:
380414
msgs = ['x.py:1: error: "int" not callable', 'foo/y.py:123: note: "X" not defined']
381415
old_msgs = ['foo/y.py:12: note: "Y" not defined', 'x.py:8: error: "str" not callable']

0 commit comments

Comments
 (0)