refactor(typing): Tighten type annotations across internal modules and cmd/git#508
Open
refactor(typing): Tighten type annotations across internal modules and cmd/git#508
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #508 +/- ##
==========================================
- Coverage 53.22% 53.12% -0.10%
==========================================
Files 38 38
Lines 5676 5688 +12
Branches 1063 1063
==========================================
+ Hits 3021 3022 +1
- Misses 2144 2154 +10
- Partials 511 512 +1 ☔ 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 - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
why: Reduce use of overly broad types for SubprocessCommand parameters. what: - Narrow _FILE to IO[str] | IO[bytes] - Specify preexec_fn returns None - Constrain pass_fds to sequence of ints
why: Reduce overly broad typing on subprocess helper parameters. what: - Narrow _FILE to IO[str] | IO[bytes] - Specify preexec_fn returns None - Constrain pass_fds to sequence of ints
…st types why: Reduce broad typing in test fixtures without changing behavior. what: - Replace varargs fixture shape with explicit cmd_args - Type expected_result as SubprocessCommand - Add CmdArgs alias for clearer argument intent
why: Keep the test fixture typing aligned with actual callable returns. what: - Replace t.Any return with str | pathlib.Path for path_type
why: Avoid unbounded Any in local VCS guard. what: - Type is_vcs input as str
why: reftag is passed to git CLI as a ref name or URL. what: - Narrow fetch() and pull() reftag to str | None
why: Document the supported shapes for git --config values. what: - Add GitConfigValue alias and use it for config parameters - Type the config stringify helper to match
why: process() always returns the input message string. what: - Type CmdLoggingAdapter.process return as tuple[str, ...]
why: Git submodule parsing returns a fixed schema. what: - Add GitSubmoduleData TypedDict - Use it for _ls() return and list typing
why: **kwargs keys are always strings for create_project. what: - Use dict[str, t.Any] for create_project overloads and impl
why: Use Collection[int] to match Python's official typeshed, allowing sets and frozensets which subprocess accepts at runtime. what: - Change pass_fds type from Sequence[int] to Collection[int] - Update both subprocess.py and run.py
why: Use Callable[[], object] to match Python's official typeshed, accepting functions that return values (which subprocess ignores). what: - Change preexec_fn return type from None to object - Update both subprocess.py and run.py
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 improves type safety across libvcs by replacing overly permissive
t.Anyannotations with more precise types:_FILE,preexec_fn, andpass_fdstype aliases to match Python's subprocess module expectationsGitConfigValuetype alias for config dict values (bool | int | float | StrPath)GitSubmoduleDataTypedDict for structured submodule status outputreftagparameter asstrinstead ofAnyCmdLoggingAdapter.process()return type andis_vcsTypeGuard input**kwargstype annotations to usedict[str, t.Any](keys are always strings)Changes
_internal/subprocess.py_FILE,preexec_fn,pass_fdstypes_internal/run.py_FILE,preexec_fn,pass_fds,CmdLoggingAdapter.process()_internal/shortcuts.py**kwargskey type,is_vcsTypeGuard inputcmd/git.pyGitConfigValue,GitSubmoduleData,reftag, config dict typestests/cmd/test_git.pytests/_internal/subprocess/test_SubprocessCommand.pyTest plan