From ed5ed3e23b1ff45098df50ec0b6da803a78289e2 Mon Sep 17 00:00:00 2001 From: David Tucker Date: Sat, 10 Aug 2024 23:51:44 -0700 Subject: [PATCH] Generalize MypyResults.from_mypy --- src/pytest_mypy.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pytest_mypy.py b/src/pytest_mypy.py index 08b26e2..4a272ff 100644 --- a/src/pytest_mypy.py +++ b/src/pytest_mypy.py @@ -252,7 +252,7 @@ def load(cls, results_f: TextIO) -> "MypyResults": @classmethod def from_mypy( cls, - items: List[MypyFileItem], + paths: List[Path], *, opts: Optional[List[str]] = None, ) -> "MypyResults": @@ -263,7 +263,7 @@ def from_mypy( if opts is None: # pragma: no cover opts = mypy_argv[:] abspath_errors = { - os.path.abspath(str(item.fspath)): [] for item in items + str(path.absolute()): [] for path in paths } # type: MypyResults._abspath_errors_type stdout, stderr, status = mypy.api.run( @@ -304,7 +304,11 @@ def from_session(cls, session) -> "MypyResults": results = cls.load(results_f) except FileNotFoundError: results = cls.from_mypy( - [item for item in session.items if isinstance(item, MypyFileItem)], + [ + Path(item.fspath) + for item in session.items + if isinstance(item, MypyFileItem) + ], ) with open(results_path, mode="w") as results_f: results.dump(results_f)