Skip to content

Conversation

@tony
Copy link
Member

@tony tony commented Jan 3, 2026

Summary

This PR systematically replaces typing.Any usages with more precise types throughout the vcspull codebase, improving type safety without changing runtime behavior.

Key changes:

  • JSON payload types: Add TypedDict definitions (PlanEntryPayload, PlanSummaryPayload, StatusResult, RepoPayload) for CLI output structures
  • Config data types: Replace dict[str, Any] with dict[str, object] for raw config data, and use Mapping[str, object] for read-only inputs
  • Type aliases: Add domain-specific aliases like JsonValue, JsonObject, RepoConfigData, SubparserTuple
  • Protocols: Add _HelpTheme protocol for formatter theme typing
  • Generic helpers: Make update_dict use bounded TypeVar to preserve return types
  • Test fixtures: Tighten fixture types with explicit config structure aliases

Files modified:

Area Files
Core config.py, _internal/config_reader.py, _internal/private_path.py, util.py
CLI cli/__init__.py, cli/_formatter.py, cli/_output.py, cli/add.py, cli/discover.py, cli/fmt.py, cli/status.py, cli/sync.py
Tests conftest.py, tests/test_cli.py, tests/cli/test_add.py, tests/cli/helpers.py

Test plan

  • All existing tests pass (uv run pytest)
  • Type checking passes (uv run mypy)
  • Linting passes (uv run ruff check .)
  • Verify no runtime behavior changes by running CLI commands manually

tony added 18 commits January 3, 2026 06:06
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
@tony tony force-pushed the improve-typings branch from 4663d11 to 40740bc Compare January 3, 2026 14:22
@codecov
Copy link

codecov bot commented Jan 3, 2026

Codecov Report

❌ Patch coverage is 86.80556% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.30%. Comparing base (f081abd) to head (2d36a25).

Files with missing lines Patch % Lines
src/vcspull/cli/sync.py 82.97% 4 Missing and 4 partials ⚠️
src/vcspull/cli/discover.py 50.00% 2 Missing and 2 partials ⚠️
src/vcspull/util.py 50.00% 2 Missing and 2 partials ⚠️
src/vcspull/cli/fmt.py 87.50% 1 Missing and 1 partial ⚠️
src/vcspull/_internal/config_reader.py 92.30% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tony
Copy link
Member Author

tony commented Jan 3, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

tony added 2 commits January 3, 2026 08:36
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
@tony
Copy link
Member Author

tony commented Jan 3, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants