Replace tracking method string constants with a TrackingMethod enum#237
Open
bbannier wants to merge 5 commits into
Open
Replace tracking method string constants with a TrackingMethod enum#237bbannier wants to merge 5 commits into
TrackingMethod enum#237bbannier wants to merge 5 commits into
Conversation
We introduce `TrackingMethod(str, Enum)` with members VERSION, BRANCH, COMMIT, BUILTIN, and DIRECTORY. Using `str` as a mixin preserves JSON round-tripping through the manifest without a custom encoder. `PackageStatus.__init__` coerces plain strings to `TrackingMethod` so existing manifests load transparently. The if/elif dispatch chains in `upgrade()` and `_is_clone_outdated()` become `match` statements with an exhaustive `case _: raise NotImplementedError` arm.
We introduce a `_GitTrackingMethod` type alias (`Literal[VERSION, BRANCH, COMMIT]`) and a `TypeGuard`-returning `_is_git_tracking_method` predicate. `GitResolution`, `_pick_version`, and `_is_clone_outdated` are updated to use this narrower type, so mypy can verify that BUILTIN and DIRECTORY never reach the Git-only `match` statements -- making `case _:` arms unnecessary. We add `typing-extensions` as a runtime dependency for `assert_never` and `TypeGuard`, both of which are available in stdlib only from Python 3.11 onward.
…tically" This reverts commit 6cbbc43ce4599642910e8af6171b39018151e29b.
BUILTIN and DIRECTORY were not tracking strategies -- they indicated the source type of a package. We remove them from the enum so `TrackingMethod` describes only how a Git clone is followed (VERSION, BRANCH, COMMIT), and non-Git packages express their state as `tracking_method=None`. Older manifests that contain "builtin" or "directory" as string values are handled in `PackageStatus.__init__`, which maps them to `None` for backward compatibility.
With `TrackingMethod` covering only Git-backed methods, non-Git packages are expressed as `tracking_method=None`. The helper reduces to a `None` check and adds no clarity over reading the condition directly. We inline it at both call sites and remove the function.
bbannier
force-pushed
the
topic/bbannier/tracking-method-enum
branch
from
July 17, 2026 12:08
3ef2bff to
dcba690
Compare
Member
Author
|
Once the enum is in place this patch presents two possible ideas:
Of course we would only merge one approach. I think I'd prefer 2) since it is conceptually simpler loosing anything in the remodel (I believe). |
bbannier
marked this pull request as ready for review
July 17, 2026 12:25
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.
The way we were storing the way a package came about with tracking method global strings was error prone. Any code using them was expected to figure out against which methods it should check. Since these were just unrelated global constants there was also no help from the type checker to make sure that handling was correct (forgot to check a variant?).
This PR cleans that up by introducing a proper Python enum, and then separating out Git-related tracking information from other concerns.
Warning
All code changes in this branch were generated with Claude Sonnet 4.6. I reviewed all changes and am accountable.