Skip to content

Commit 47e5bfc

Browse files
kdeldyckeclaude
andcommitted
Fix 32 mypy errors in test files
Resolve type-checking failures caught by lint.yaml's "Lint types" job: - test_matrix: suppress arg-type/list-item on intentional negative tests, widen tuple type after prune() to avoid false unreachable from length narrowing - test_metadata: annotate expected dict as dict[str, Any] to prevent narrowing cascade, suppress StrEnum arg-type on Dialect members - test_help: replace click.BaseCommand (not recognized by mypy) with click.Group | click.Command - test_git_ops: suppress arg-type on intentional invalid "patch" argument - test_binary: annotate empty dict for mypy inference - test_checksums: assert binary_spec.binary is not None before access - test_init_project: assert isinstance for ToolConfigComponent narrowing, annotate mixed-type dict for _serialize_array_entries Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e09c0da commit 47e5bfc

File tree

7 files changed

+29
-16
lines changed

7 files changed

+29
-16
lines changed

tests/test_binary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def test_missing_field(tmp_path):
125125
binary.touch()
126126

127127
# Return empty metadata.
128-
mock_output = {}
128+
mock_output: dict[str, str] = {}
129129
with (
130130
patch("repomatic.binary.run_exiftool", return_value=mock_output),
131131
pytest.raises(AssertionError, match="Binary architecture mismatch"),

tests/test_checksums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def test_update_registry_checksums_replaces_stale_hash(tmp_path):
136136
binary_spec = spec
137137
break
138138
assert binary_spec is not None
139+
assert binary_spec.binary is not None
139140

140141
old_hash = next(iter(binary_spec.binary.checksums.values()))
141142

tests/test_git_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def test_is_version_bump_allowed_returns_bool():
236236
def test_is_version_bump_allowed_invalid_part():
237237
"""Test that is_version_bump_allowed raises for invalid parts."""
238238
with pytest.raises(ValueError, match="Invalid version part"):
239-
is_version_bump_allowed("patch")
239+
is_version_bump_allowed("patch") # type: ignore[arg-type]
240240

241241

242242
def test_is_version_bump_allowed_current_repo():

tests/test_help.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
def _collect_commands(
29-
group: click.BaseCommand,
29+
group: click.Group | click.Command,
3030
prefix: tuple[str, ...] = (),
3131
) -> list[tuple[str, ...]]:
3232
"""Recursively collect all command paths from a Click group."""

tests/test_init_project.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,9 @@ def test_skips_already_dev_version(tmp_path: Path) -> None:
10751075
pyproject = tmp_path / "pyproject.toml"
10761076
pyproject.write_text(content, encoding="UTF-8")
10771077

1078-
result = _update_tool_config(content, _BY_NAME["bumpversion"], pyproject)
1078+
bv = _BY_NAME["bumpversion"]
1079+
assert isinstance(bv, ToolConfigComponent)
1080+
result = _update_tool_config(content, bv, pyproject)
10791081

10801082
assert result is not None
10811083
# Version should not be double-suffixed.
@@ -1136,7 +1138,9 @@ def test_preserves_local_array_entries(tmp_path: Path) -> None:
11361138
pyproject = tmp_path / "pyproject.toml"
11371139
pyproject.write_text(content, encoding="UTF-8")
11381140

1139-
result = _update_tool_config(content, _BY_NAME["bumpversion"], pyproject)
1141+
bv = _BY_NAME["bumpversion"]
1142+
assert isinstance(bv, ToolConfigComponent)
1143+
result = _update_tool_config(content, bv, pyproject)
11401144

11411145
assert result is not None
11421146
parsed = tomllib.loads(result)
@@ -1164,6 +1168,7 @@ def test_ongoing_sync_idempotent_with_local_entries(tmp_path: Path) -> None:
11641168
'replace = "example.com/v{new_version}/"\n'
11651169
)
11661170
bv_comp = _BY_NAME["bumpversion"]
1171+
assert isinstance(bv_comp, ToolConfigComponent)
11671172
pyproject = tmp_path / "pyproject.toml"
11681173
pyproject.write_text(content, encoding="UTF-8")
11691174

@@ -1212,7 +1217,7 @@ def test_local_array_entries_detection() -> None:
12121217

12131218
def test_serialize_array_entries_roundtrip() -> None:
12141219
"""Verify serialized entries produce valid TOML that parses back."""
1215-
entries = [
1220+
entries: list[dict] = [
12161221
{"filename": "./readme.md", "ignore_missing_version": True, "search": "a"},
12171222
{"filename": "./docs/tutorial.md", "search": 'has "quotes"'},
12181223
]

tests/test_matrix.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ def test_matrix():
5454
assert repr(matrix) == "<Matrix: FrozenDict({'foo': ('a', 'b', 'c', 'd')})>"
5555

5656
with pytest.raises(ValueError):
57-
matrix.add_variation("variation_1", None)
57+
matrix.add_variation("variation_1", None) # type: ignore[arg-type]
5858

5959
with pytest.raises(ValueError):
6060
matrix.add_variation("variation_1", [])
6161

6262
with pytest.raises(ValueError):
63-
matrix.add_variation("variation_1", [None])
63+
matrix.add_variation("variation_1", [None]) # type: ignore[list-item]
6464

6565
with pytest.raises(ValueError):
6666
matrix.add_variation("include", ["a", "b", "c"])
@@ -140,9 +140,15 @@ def test_prune(caplog):
140140
matrix.prune()
141141

142142
# Only the effective exclude and the non-axis-key exclude remain.
143-
assert len(matrix.exclude) == 2
144-
assert {"os": "macos-26", "version": "3.10"} in matrix.exclude
145-
assert {"state": "unstable"} in matrix.exclude
143+
# Reassign with an explicit annotation to widen the type back to a
144+
# variable-length tuple. The ``assert len(...) == 4`` above narrows
145+
# ``matrix.exclude`` to a fixed-length 4-tuple; mypy cannot track the
146+
# mutation performed by ``prune()``, so without this it considers the
147+
# ``len(...) == 2`` assert unreachable.
148+
exclude: tuple[dict[str, str], ...] = matrix.exclude
149+
assert len(exclude) == 2
150+
assert {"os": "macos-26", "version": "3.10"} in exclude
151+
assert {"state": "unstable"} in exclude
146152

147153
assert "Dropping no-op exclude" in caplog.text
148154
assert "'windows-11-arm'" in caplog.text

tests/test_metadata.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def iter_checks(metadata: Any, expected: Any, context: Any) -> None:
383383
assert type(metadata) is type(expected)
384384

385385

386-
expected = {
386+
expected: dict[str, Any] = {
387387
"is_bot": AnyBool(),
388388
# skip_binary_build depends on the event type and changed files. In CI push events
389389
# where only non-binary-affecting files changed, it is True.
@@ -917,7 +917,7 @@ def iter_checks(metadata: Any, expected: Any, context: Any) -> None:
917917

918918

919919
def test_metadata_github_json_format():
920-
raw = Metadata().dump(Dialect.github_json)
920+
raw = Metadata().dump(Dialect.github_json) # type: ignore[arg-type]
921921
assert isinstance(raw, str)
922922

923923
# Output must be a single line starting with "metadata=".
@@ -956,7 +956,8 @@ def test_metadata_github_json_format():
956956

957957
def test_metadata_github_json_format_key_filtering():
958958
raw = Metadata().dump(
959-
Dialect.github_json, keys=("is_python_project", "current_version")
959+
Dialect.github_json, # type: ignore[arg-type]
960+
keys=("is_python_project", "current_version"),
960961
)
961962
json_str = raw.strip().removeprefix("metadata=")
962963
metadata = json.loads(json_str)
@@ -965,7 +966,7 @@ def test_metadata_github_json_format_key_filtering():
965966

966967

967968
def test_metadata_json_format():
968-
metadata = Metadata().dump(Dialect.json)
969+
metadata = Metadata().dump(Dialect.json) # type: ignore[arg-type]
969970
assert isinstance(metadata, str)
970971

971972
iter_checks(json.loads(metadata), expected, metadata)
@@ -1703,7 +1704,7 @@ def test_config_reference():
17031704
for f in dc_fields(Config):
17041705
default = f.default_factory() if f.default_factory is not MISSING else f.default
17051706
if hasattr(default, "__dataclass_fields__"):
1706-
expected_rows += len(dc_fields(type(default)))
1707+
expected_rows += len(dc_fields(type(default))) # type: ignore[arg-type]
17071708
else:
17081709
expected_rows += 1
17091710
assert len(rows) == expected_rows

0 commit comments

Comments
 (0)