refactor(typing): Replace Any with precise types across codebase#495
Open
refactor(typing): Replace Any with precise types across codebase#495
Conversation
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: Replace t.Any theme annotations with explicit attributes used by the formatter. what: - Add _HelpTheme protocol for heading/option color fields - Cast _theme to the protocol type when reading - Use _HelpTheme in _colorize_example_line
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: Reflect the workspace->repo mapping shape and allow simple repo shorthands. what: - Define RawConfigDict/RawRepoConfigValue aliases with nested dict patterns - Accept pathlib.Path shorthand in extract_repos without type errors - Narrow config reader key type and simplify test typing
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: Tighten config helper signatures while keeping flexible mapping inputs. what: - Use object/Mapping in save/merge/normalize helpers - Cast repo names to str when building paths - Keep deep-merge behavior intact
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: Make loader and duplicate-tracking types safer without changing behavior. what: - Use object-typed mappings for raw config data - Tighten duplicate tracking payload 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
why: RawConfig type expects serializable primitives, not GitRemote objects. what: - Replace GitRemote instantiation with plain dict containing fetch_url/push_url - Remove unused GitRemote import
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #495 +/- ##
==========================================
+ Coverage 79.24% 79.30% +0.05%
==========================================
Files 15 15
Lines 1980 2029 +49
Branches 404 407 +3
==========================================
+ Hits 1569 1609 +40
- Misses 267 273 +6
- Partials 144 147 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
why: CLAUDE.md requires namespace imports for typing modules. what: - Change `from typing_extensions import X` to `import typing_extensions` - Update all usages to use `typing_extensions.X` namespace
why: Return type was GitSync but function returns GitSync | HgSync | SvnSync.
what:
- Add HgSync and SvnSync imports from libvcs
- Change return type to union GitSync | HgSync | SvnSync
- Remove incorrect t.cast("GitSync", ...) wrappers
- Remove resolved TODO comment
- Add casts in tests that access GitSync-specific methods
Member
Author
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 .)