Skip to content

Reject NaN against a declared float bound - #280

Open
dylanpulver wants to merge 1 commit into
DiffSK:5.0.xfrom
dylanpulver:fix-float-bounds-nan
Open

Reject NaN against a declared float bound#280
dylanpulver wants to merge 1 commit into
DiffSK:5.0.xfrom
dylanpulver:fix-float-bounds-nan

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Sep 1, 2026

Copy link
Copy Markdown

is_float bounds-checks with value < min_val / value > max_val (src/configobj/validate.py:843-846). Every comparison against NaN is False, so a NaN violates neither test and is returned as valid, while inf and -inf are correctly rejected by those same bounds.

The fix phrases each check as must satisfy the bound rather than must not violate it, so NaN fails. An unbounded float still accepts NaN, pinned by a test. is_integer is unaffected, since it converts through int() before any bound is compared.

One choice worth your word: with a bound declared, NaN now raises VdtValueTooSmallError, which follows from the ordering rather than from a claim that NaN is "too small". Say so and I'll make it VdtTypeError.

python -m pytest src/tests/ -q on 5.0.x: 76 passed clean, 2 failed with the new tests added alone, 80 passed with this PR.

Based on 5.0.x rather than release, since #275, #276, #278 all merged there.

AI disclosure: found and drafted with Claude Code (Claude Opus 5, claude-opus-5). Reviewed before submission.

is_float compared with `value < min_val` / `value > max_val`. Every
comparison against NaN is False, so a NaN satisfied neither test and was
returned as valid: `float(0, 10)` accepts the string 'nan', while 'inf' and
'-inf' are correctly rejected by those same bounds.

docs/validate.rst describes these parameters as "any value from 3 to 9"
(integer, and float "has the same parameters"), which NaN is not.

Phrase the checks as "must satisfy the bound" instead, so NaN fails them. An
unbounded `float` still accepts NaN, unchanged. is_integer is unaffected: it
converts through int() first, which rejects NaN before any bound is compared.
@jelmer

jelmer commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Please keep PR descriptions brief and to the point.

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