Skip to content

fix: reject NaN values in FloatRange#3348

Closed
PewterZz wants to merge 1 commit into
pallets:mainfrom
PewterZz:fix-float-range-nan
Closed

fix: reject NaN values in FloatRange#3348
PewterZz wants to merge 1 commit into
pallets:mainfrom
PewterZz:fix-float-range-nan

Conversation

@PewterZz
Copy link
Copy Markdown

Fixes #3347

FloatRange currently accepts NaN because NaN comparisons (NaN < min, NaN > max) always return False, causing the range check to pass. This bypasses validation entirely, including clamp=True mode.

The fix adds a math.isnan check in FloatRange.convert before returning the value. NaN is not a valid number for any range, so it should always be rejected.

Change summary:

  • Override convert in FloatRange to check for NaN after calling super().convert()
  • Fail with "nan is not a valid number" if detected
  • 6 new test cases covering bounded, unbounded, clamped, and open-bound FloatRange configurations

All 1391 tests pass.

@davidism
Copy link
Copy Markdown
Member

AI slop. I don't see why it matters if we accept all float values, and if certain values that are known not to compare don't compare.

@davidism davidism closed this Apr 17, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FloatRange accepts NaN, bypassing range validation

2 participants