Skip to content

Commit 9170be0

Browse files
committed
test: fix mypy type errors in preserve tests
`test_tools.py::test_types` runs `mypy .` over the whole tree and flagged three `_apply_regions` calls in `tests/test_preserve.py`: the local dicts were inferred as `dict[str, str]`, which is not assignable to the expected `dict[_RegionKey, str]` because `dict` is invariant in its key type. Annotate the three test dicts with `_RegionKey` so they match the parameter type.
1 parent 405786b commit 9170be0

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tests/test_preserve.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PreserveMarkerError,
1515
_apply_regions,
1616
_parse_regions,
17+
_RegionKey,
1718
capture_preserved_regions,
1819
find_marker_files,
1920
restore_preserved_regions,
@@ -59,7 +60,7 @@ def test_apply_regions_replaces_only_matching_bodies() -> None:
5960
f"# {PRESERVE_START_TOKEN} keep\nUSER\n# {PRESERVE_END_TOKEN} keep\n"
6061
f"# {PRESERVE_START_TOKEN} other\nOTHER-USER\n# {PRESERVE_END_TOKEN} other\n"
6162
)
62-
captured = {
63+
captured: dict[_RegionKey, str] = {
6364
key: region.body
6465
for key, region in zip(("keep", "other"), _parse_regions(original), strict=True)
6566
}
@@ -77,15 +78,15 @@ def test_apply_regions_replaces_only_matching_bodies() -> None:
7778

7879

7980
def test_apply_regions_keeps_updated_marker_lines() -> None:
80-
captured = {"x": "USER\n"}
81+
captured: dict[_RegionKey, str] = {"x": "USER\n"}
8182
# Template moved the region and changed the marker's comment style.
8283
new_render = f"// {PRESERVE_START_TOKEN} x\nTEMPLATE\n// {PRESERVE_END_TOKEN} x\n"
8384
result = _apply_regions(new_render, captured)
8485
assert result == f"// {PRESERVE_START_TOKEN} x\nUSER\n// {PRESERVE_END_TOKEN} x\n"
8586

8687

8788
def test_apply_regions_ignores_new_region() -> None:
88-
captured: dict[str, str] = {} # nothing captured
89+
captured: dict[_RegionKey, str] = {} # nothing captured
8990
new_render = (
9091
f"# {PRESERVE_START_TOKEN} fresh\nDUMMY\n# {PRESERVE_END_TOKEN} fresh\n"
9192
)

0 commit comments

Comments
 (0)