Raise LengthInvalid (not RangeInvalid) for non-sized values in Length - #551
Open
uttam12331 wants to merge 1 commit into
Open
Raise LengthInvalid (not RangeInvalid) for non-sized values in Length#551uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
Length.__call__ raises LengthInvalid for its min/max length checks, but its `except TypeError` handler (hit when the value has no len(), e.g. None or an int) raises RangeInvalid instead -- a copy-paste leftover from the Clamp validator above, which is genuinely a range operation. Passing a non-sized value to a Length validator therefore reports a range error rather than a length error, inconsistent with the validator's own two other error paths. Raise LengthInvalid, and tighten test_length_invalid to assert the error type.
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
Length.__call__raisesLengthInvalidfor its length checks, but theexcept TypeErrorhandler raisesRangeInvalid:When a value with no
len()(e.g.None, or anint) is passed to aLengthvalidator, the error is reported as a range error rather than a length error — inconsistent with the validator's own two other error paths.This looks like a copy-paste leftover from the
Clampvalidator directly above, which is genuinely a range operation and correctly raisesRangeInvalidin its ownexcept TypeError.Fix
LengthInvalidis already imported at the top of the module.Tests
Tightened
test_length_invalidto assert the raised error is aLengthInvalid. It fails on the previous behavior (RangeInvalid) and passes with the fix. Full suite: 181 passed.