Skip to content

AI spam#3541

Closed
tan7vir wants to merge 1 commit into
pallets:mainfrom
tan7vir:fix-intrange-clamp-docstring
Closed

AI spam#3541
tan7vir wants to merge 1 commit into
pallets:mainfrom
tan7vir:fix-intrange-clamp-docstring

Conversation

@tan7vir
Copy link
Copy Markdown

@tan7vir tan7vir commented May 31, 2026

The IntRange docstring describes the clamp option as:

If clamp is enabled, a value outside the range is clamped to the boundary instead of failing.

This is inaccurate when a boundary is open. Because an open boundary value is itself excluded from the range, IntRange._clamp returns bound + dir for open ends, i.e. it clamps to the nearest integer that is still inside the range — not to the boundary value.

Reproduction

import click

# closed boundary: clamps to the boundary, as documented
click.IntRange(0, 5, clamp=True).convert("6", None, None)                  # -> 5

# open boundary: clamps to the nearest in-range integer, NOT the boundary
click.IntRange(0, 5, max_open=True, clamp=True).convert("6", None, None)   # -> 4
click.IntRange(0, 5, min_open=True, clamp=True).convert("-3", None, None)  # -> 1

With max_open=True, the documented "clamped to the boundary" would give 5, but 5 is excluded from the range, so the actual (and correct) result is 4. The current docstring does not mention this.

Change

Adds one clarifying sentence to the IntRange docstring so it matches IntRange._clamp. Documentation only — no behavior change.

Validation

Confirmed the behavior above against the current source; click imports cleanly after the change.

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.
@davidism davidism closed this May 31, 2026
@davidism davidism changed the title docs: clarify IntRange clamp behavior for open bounds AI spam May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants