diff --git a/mypy/suggestions.py b/mypy/suggestions.py index 39a220e34091..781e505177ec 100644 --- a/mypy/suggestions.py +++ b/mypy/suggestions.py @@ -308,6 +308,7 @@ def restore_after(self, module: str) -> Iterator[None]: try: yield finally: + self.manager.errors.reset() self.reload(self.graph[module]) @contextmanager diff --git a/mypy/test/testfinegrained.py b/mypy/test/testfinegrained.py index 8a93018e39b3..d0927ae9f5a1 100644 --- a/mypy/test/testfinegrained.py +++ b/mypy/test/testfinegrained.py @@ -17,7 +17,9 @@ import os import re import sys +import tempfile import unittest +from pathlib import Path from typing import Any import pytest @@ -376,6 +378,38 @@ def normalize_messages(messages: list[str]) -> list[str]: class TestMessageSorting(unittest.TestCase): + def test_suggest_callsites_with_existing_messages(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + tmp_path = Path(tmp) + source_path = tmp_path / "main.py" + source_path.write_text("reveal_type(1)\n", encoding="utf8") + options = Options() + options.follow_imports = "normal" + options.use_builtins_fixtures = False + options.error_summary = False + server = Server(options, str(tmp_path / "dmypy.status")) + + result = server.check( + [BuildSource(str(source_path), "__main__", None)], + export_types=False, + is_tty=False, + terminal_width=-1, + ) + assert result["status"] == 0 + + response = server.cmd_suggest( + "os.path.islink", + json=False, + no_any=False, + no_errors=False, + flex_any=None, + use_fixme=None, + callsites=True, + max_guesses=None, + ) + assert response.get("status") == 0 + assert "error" not in response + def test_simple_sorting(self) -> None: msgs = ['x.py:1: error: "int" not callable', 'foo/y.py:123: note: "X" not defined'] old_msgs = ['foo/y.py:12: note: "Y" not defined', 'x.py:8: error: "str" not callable']