diff --git a/pytest_mypy_plugins/item.py b/pytest_mypy_plugins/item.py index be50b1f..922f400 100644 --- a/pytest_mypy_plugins/item.py +++ b/pytest_mypy_plugins/item.py @@ -401,7 +401,11 @@ def remove_cache_files(self, fpath_no_suffix: Path) -> None: pass store.commit() finally: - store.close() + # ``MetadataStore.close`` was added in mypy 1.20; guard for older + # mypy versions that are still within our supported range (>=1.3). + close = getattr(store, "close", None) + if close is not None: + close() def execute_extension_hook(self) -> None: extension_hook_fqname = self.config.option.mypy_extension_hook diff --git a/pytest_mypy_plugins/tests/test_mypy_cache.py b/pytest_mypy_plugins/tests/test_mypy_cache.py index 22773d3..70aac48 100644 --- a/pytest_mypy_plugins/tests/test_mypy_cache.py +++ b/pytest_mypy_plugins/tests/test_mypy_cache.py @@ -224,6 +224,9 @@ def get_created_cache_files(cache_dir: Path, module_rel_paths_no_suffix: tuple[s if any(entry.startswith(rel_path + ".") for rel_path in module_rel_paths_no_suffix): created.append(entry) finally: - store.close() + # See PR #188: mypy < 1.20 does not have MetadataStore.close + close = getattr(store, "close", None) + if close is not None: + close() return created