Repository navigation
Raise IndexError for slices selecting undefined version parts - #535
Open
SonicHedghog wants to merge 1 commit into
Open
SonicHedghog wants to merge 1 commit into
SonicHedghog wants to merge 1 commit into
Conversation
Version slicing silently dropped undefined parts from the result, contradicting the documented behavior that requesting an undefined part of a range raises IndexError. A slice now applies normal Python slicing semantics to determine the selected positions and raises IndexError when any selected position is undefined, consistent with scalar indexing. Stepped slices inspect only the positions they actually select. Fixes python-semver#529
This branch has not been deployed
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.
Fixes #529
Summary
Versionslicing silently dropped undefined parts instead of raising the documentedIndexError:Following the direction confirmed in the issue, a slice now applies normal Python slicing semantics to determine the selected positions — including clamping of out-of-range bounds — and raises
IndexErrorwhen any selected position is undefined:Scalar indexing behavior is unchanged: out-of-range and undefined positions raise exactly as before, and negative indices remain unsupported.
Compatibility notes
Version.parse("1.2.3")[0:10] == (1, 2, 3)intests/test_index.pyencoded the undocumented dropping behavior; it is updated to the documented raising behavior, with new regression coverage for partially undefined selections, over-long slices, and stepped slices in both directions.v[3:4]on a version with a prerelease), preserving the current API; as noted in the issue this is not idiomatic, but changing it would be a separate breaking change and can be decided independently.Tests