Skip to content

Raise Invalid for non-finite Number values - #543

Closed
CodingFeng101 wants to merge 1 commit into
alecthomas:masterfrom
CodingFeng101:codex/number-non-finite-invalid
Closed

Raise Invalid for non-finite Number values#543
CodingFeng101 wants to merge 1 commit into
alecthomas:masterfrom
CodingFeng101:codex/number-non-finite-invalid

Conversation

@CodingFeng101

Copy link
Copy Markdown

Fixes #541.

What changed

Number now rejects non-finite Decimal values such as Infinity and NaN with Invalid instead of leaking the internal TypeError from precision inspection.

Why

Number is a validator and callers expect validation failures to surface as voluptuous Invalid / MultipleInvalid. Non-finite numeric strings currently escape that contract when precision or scale checking is enabled.

Validation

  • python -m pytest voluptuous\tests\tests.py::test_number_validation_with_string voluptuous\tests\tests.py::test_number_validation_with_non_finite_number voluptuous\tests\tests.py::test_number_validation_with_invalid_precision_invalid_scale -q
  • python -m pytest voluptuous\tests\tests.py -q
  • python -m py_compile voluptuous\validators.py voluptuous\tests\tests.py
  • git diff --check

@alecthomas

Copy link
Copy Markdown
Owner

Thanks, but #542 already addresses this and was raised first.

@alecthomas alecthomas closed this Jul 5, 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.

Number validator leaks a raw TypeError on Infinity/NaN instead of raising Invalid

2 participants