Skip to content

Commit f123f95

Browse files
committed
cli/fmt(refactor[typing]): Narrow repo config inputs
why: Make formatter typing reflect the config shapes it actually handles. what: - Define RepoConfigData as str/path/mapping inputs - Normalize mapping inputs without redundant casts
1 parent 577a6a7 commit f123f95

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/vcspull/cli/fmt.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
log = logging.getLogger(__name__)
2828

29+
RepoConfigData: t.TypeAlias = str | pathlib.Path | t.Mapping[str, object]
30+
2931

3032
class FmtAction(enum.Enum):
3133
"""Action resolved for each repo entry during ``vcspull fmt``."""
@@ -64,12 +66,12 @@ def create_fmt_subparser(parser: argparse.ArgumentParser) -> None:
6466
parser.set_defaults(merge_roots=True)
6567

6668

67-
def normalize_repo_config(repo_data: object) -> dict[str, object]:
69+
def normalize_repo_config(repo_data: RepoConfigData) -> dict[str, object]:
6870
"""Normalize repository configuration to verbose format.
6971
7072
Parameters
7173
----------
72-
repo_data : Any
74+
repo_data : str | pathlib.Path | Mapping[str, object]
7375
Repository configuration (string URL or dict)
7476
7577
Returns
@@ -104,16 +106,16 @@ def normalize_repo_config(repo_data: object) -> dict[str, object]:
104106
if isinstance(repo_data, str):
105107
# Convert compact format to verbose format
106108
return {"repo": repo_data}
107-
if isinstance(repo_data, dict):
108-
# If it has 'url' key but not 'repo', convert to use 'repo'
109-
if "url" in repo_data and "repo" not in repo_data:
110-
normalized = repo_data.copy()
111-
normalized["repo"] = normalized.pop("url")
112-
return normalized
113-
# Already in correct format or has other fields
114-
return t.cast("dict[str, object]", repo_data)
115-
# Return as-is for other types
116-
return t.cast("dict[str, object]", repo_data)
109+
if isinstance(repo_data, pathlib.Path):
110+
return {"repo": str(repo_data)}
111+
repo_map = dict(repo_data)
112+
# If it has 'url' key but not 'repo', convert to use 'repo'
113+
if "url" in repo_map and "repo" not in repo_map:
114+
normalized = repo_map.copy()
115+
normalized["repo"] = normalized.pop("url")
116+
return normalized
117+
# Already in correct format or has other fields
118+
return repo_map
117119

118120

119121
def _classify_fmt_action(repo_data: t.Any) -> tuple[FmtAction, t.Any]:

0 commit comments

Comments
 (0)