refactor(typing): Replace Any with precise types across codebase#495
refactor(typing): Replace Any with precise types across codebase#495tony wants to merge 13 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #495 +/- ##
==========================================
- Coverage 83.30% 83.27% -0.03%
==========================================
Files 32 32
Lines 4492 4515 +23
Branches 903 904 +1
==========================================
+ Hits 3742 3760 +18
- Misses 499 502 +3
- Partials 251 253 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
1 similar comment
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
|
Rebased onto current Dropped as superseded/obsolete:
Adapted to current master:
Net: the precise |
why: Replace t.Any in create_parser returns with explicit subparser tuple typing. what: - Add SubparserTuple type alias for six CLI subparsers - Use the alias in create_parser overloads and return annotation
why: Remove unused object parameters for a clearer, specific API. what: - Narrow CouldNotGuessVCSFromURL.__init__ to repo_url only
why: Make plan/output JSON structures explicit for safer indexing and clearer contracts. what: - Introduce JsonValue aliases plus typed payloads for plan entry/summary/result - Type OutputFormatter payload handling and cast summary/status payloads - Adjust plan output tests for TypedDict iteration
why: Make status payload shape explicit and reuse it in sync plan logic/tests. what: - Define StatusResult and update status helpers to return it - Accept StatusResult in sync plan action selection - Update status/sync plan tests to build typed status inputs
why: Use object/TypedDict shapes for raw config sections without changing runtime behavior. what: - Add OrderedItem typed dict for label/section entries in add flow - Replace raw config/duplicate annotations with object-based types - Tighten discover workspace section handling with casts
why: Reduce Any usage in fixtures/helpers and align log formatter signature with stdlib. what: - Use object for doctest namespace and raw test loader return - Narrow is_valid_config input type for type guard usage - Replace LogFormatter kwargs with explicit stdlib-compatible params
why: Clarify JSON payload typing for per-repo sync events. what: - Type sync event payload dict with JsonValue entries
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
why: Preserve return type while accepting any mapping inputs safely. what: - Use MutableMapping-bounded TypeVar and Mapping input - Handle existing nested mappings with safe fallbacks
why: Make CLI test fixtures and plan helper kwargs type-safe for better mypy coverage. what: - Add explicit config structure aliases in CLI tests - Use a TypedDict for PlanEntry kwargs and a typed subprocess args alias
why: Improve type precision for JSON payload checks and config fixtures in tests. what: - Add JSON/config type aliases for CLI plan tests - Tighten fixture protocol and config writer entry types
why: Remove remaining Any usages while keeping repo sync behavior unchanged. what: - Add typed payload helpers for libvcs create_project calls - Tighten PrivatePath constructor argument types
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
Summary
This PR systematically replaces
typing.Anyusages with more precise types throughout the vcspull codebase, improving type safety without changing runtime behavior.Key changes:
TypedDictdefinitions (PlanEntryPayload,PlanSummaryPayload,StatusResult,RepoPayload) for CLI output structuresdict[str, Any]withdict[str, object]for raw config data, and useMapping[str, object]for read-only inputsJsonValue,JsonObject,RepoConfigData,SubparserTuple_HelpThemeprotocol for formatter theme typingupdate_dictuse boundedTypeVarto preserve return typesFiles modified:
config.py,_internal/config_reader.py,_internal/private_path.py,util.pycli/__init__.py,cli/_formatter.py,cli/_output.py,cli/add.py,cli/discover.py,cli/fmt.py,cli/status.py,cli/sync.pyconftest.py,tests/test_cli.py,tests/cli/test_add.py,tests/cli/helpers.pyTest plan
uv run pytest)uv run mypy)uv run ruff check .)