Skip to content

Commit d50649a

Browse files
committed
cli/fmt(refactor[typing]): Use object/Mapping for config input
why: Replace Any in formatting helpers while still accepting varied config dict shapes. what: - Type normalize_repo_config/format_config with object and Mapping inputs - Update fmt tests to match new config_factory signatures
1 parent 8c209c2 commit d50649a

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/vcspull/cli/fmt.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_fmt_subparser(parser: argparse.ArgumentParser) -> None:
5353
parser.set_defaults(merge_roots=True)
5454

5555

56-
def normalize_repo_config(repo_data: t.Any) -> dict[str, t.Any]:
56+
def normalize_repo_config(repo_data: object) -> dict[str, object]:
5757
"""Normalize repository configuration to verbose format.
5858
5959
Parameters
@@ -76,12 +76,14 @@ def normalize_repo_config(repo_data: t.Any) -> dict[str, t.Any]:
7676
normalized["repo"] = normalized.pop("url")
7777
return normalized
7878
# Already in correct format or has other fields
79-
return repo_data
79+
return t.cast("dict[str, object]", repo_data)
8080
# Return as-is for other types
81-
return t.cast("dict[str, t.Any]", repo_data)
81+
return t.cast("dict[str, object]", repo_data)
8282

8383

84-
def format_config(config_data: dict[str, t.Any]) -> tuple[dict[str, t.Any], int]:
84+
def format_config(
85+
config_data: t.Mapping[str, object],
86+
) -> tuple[dict[str, object], int]:
8587
"""Format vcspull configuration for consistency.
8688
8789
Parameters
@@ -95,7 +97,7 @@ def format_config(config_data: dict[str, t.Any]) -> tuple[dict[str, t.Any], int]
9597
Formatted configuration and count of changes made
9698
"""
9799
changes = 0
98-
formatted: dict[str, t.Any] = {}
100+
formatted: dict[str, object] = {}
99101

100102
# Sort directories
101103
sorted_dirs = sorted(config_data.keys())
@@ -109,11 +111,12 @@ def format_config(config_data: dict[str, t.Any]) -> tuple[dict[str, t.Any], int]
109111
continue
110112

111113
# Sort repositories within each directory
112-
sorted_repos = sorted(repos.keys())
113-
formatted_dir: dict[str, t.Any] = {}
114+
repos_map = t.cast("dict[str, object]", repos)
115+
sorted_repos = sorted(repos_map.keys())
116+
formatted_dir: dict[str, object] = {}
114117

115118
for repo_name in sorted_repos:
116-
repo_data = repos[repo_name]
119+
repo_data = repos_map[repo_name]
117120
normalized = normalize_repo_config(repo_data)
118121

119122
# Check if normalization changed anything

tests/cli/test_fmt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class WorkspaceRootFixture(t.NamedTuple):
2828
"""Fixture for workspace root normalization cases."""
2929

3030
test_id: str
31-
config_factory: t.Callable[[pathlib.Path], dict[str, t.Any]]
31+
config_factory: t.Callable[[pathlib.Path], dict[str, object]]
3232

3333

3434
WORKSPACE_ROOT_FIXTURES: list[WorkspaceRootFixture] = [
@@ -81,7 +81,7 @@ class WorkspaceRootFixture(t.NamedTuple):
8181
)
8282
def test_workspace_root_normalization(
8383
test_id: str,
84-
config_factory: t.Callable[[pathlib.Path], dict[str, t.Any]],
84+
config_factory: t.Callable[[pathlib.Path], dict[str, object]],
8585
snapshot_json: SnapshotAssertion,
8686
) -> None:
8787
"""Ensure format_config merges duplicate workspace roots."""

0 commit comments

Comments
 (0)