Conversation
The IntRange docstring states that with clamp enabled an out-of-range value is "clamped to the boundary." That is inaccurate when a boundary is open: since the open boundary value is excluded from the range, IntRange._clamp returns bound + dir, clamping to the nearest integer that is still inside the range rather than to the boundary itself. For example, IntRange(0, 5, max_open=True, clamp=True) clamps 6 to 4 (not 5) and IntRange(0, 5, min_open=True, clamp=True) clamps -3 to 1 (not 0). Document this so the description matches IntRange._clamp.
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
IntRangedocstring describes theclampoption as:This is inaccurate when a boundary is open. Because an open boundary value is itself excluded from the range,
IntRange._clampreturnsbound + dirfor open ends, i.e. it clamps to the nearest integer that is still inside the range — not to the boundary value.Reproduction
With
max_open=True, the documented "clamped to the boundary" would give5, but5is excluded from the range, so the actual (and correct) result is4. The current docstring does not mention this.Change
Adds one clarifying sentence to the
IntRangedocstring so it matchesIntRange._clamp. Documentation only — no behavior change.Validation
Confirmed the behavior above against the current source;
clickimports cleanly after the change.