fix(version): raise InvalidVersion for non-str pre letters in from_parts - #1241
Merged
Merged
Conversation
`_validate_pre` normalized the letter with `.lower()` before any type check, so a non-string first element escaped as `AttributeError` instead of `InvalidVersion`: `Version.from_parts(release=(1,), pre=(1, 1))`. The letter is now type-checked before it is normalized, matching how the sibling validators report bad types. Assisted-by: ClaudeCode:claude-opus-4-8 Assisted-by: ClaudeCode:claude-fable-5
henryiii
force-pushed
the
fix/from-parts-bool-validation
branch
from
June 10, 2026 23:23
b01587d to
dd7789a
Compare
notatallshaw
approved these changes
Jul 8, 2026
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.
I removed the bool rejection; I don't think rejecting bools is Pythonic.
🤖 AI text below 🤖
Part of #1239.
_validate_pre(reachable throughVersion.from_partsand__replace__) normalized the pre letter with.lower()before any type check, so a non-string first element escaped asAttributeErrorinstead ofInvalidVersion:The letter is now type-checked before it is normalized, so the call raises
InvalidVersionlike the sibling validators do for bad types. A regression test is included.This PR originally also rejected
boolwhere the validators expect anint(e.g.post=Trueproducing1.postTrue); that part was dropped as it is arguably just a quirk of Python rather than a validation gap.🤖 Generated with Claude Code