Skip to content

Handle integer-valued float multipleOf divisors exactly#1477

Open
ShipItAndPray wants to merge 1 commit intopython-jsonschema:mainfrom
ShipItAndPray:fix-1159-integer-valued-multipleof-floats
Open

Handle integer-valued float multipleOf divisors exactly#1477
ShipItAndPray wants to merge 1 commit intopython-jsonschema:mainfrom
ShipItAndPray:fix-1159-integer-valued-multipleof-floats

Conversation

@ShipItAndPray
Copy link
Copy Markdown

Summary

  • treat integer-valued float multipleOf divisors with exact integer modulo logic
  • keep the existing float fast path and Fraction fallback for non-integer float divisors
  • add regression coverage for large integers across validator drafts

Reproduction

from jsonschema import validate

validate(9007199254740995, {"type": "integer", "multipleOf": 11})
validate(9007199254740995, {"type": "integer", "multipleOf": 11.0})

Before this change, the second validation incorrectly failed.

Closes #1159

Testing

  • uv run python -m unittest jsonschema.tests.test_validators.TestDraft3Validator.test_large_integer_multiple_of_integer_valued_float jsonschema.tests.test_validators.TestDraft4Validator.test_large_integer_multiple_of_integer_valued_float jsonschema.tests.test_validators.TestDraft6Validator.test_large_integer_multiple_of_integer_valued_float jsonschema.tests.test_validators.TestDraft7Validator.test_large_integer_multiple_of_integer_valued_float jsonschema.tests.test_validators.TestDraft201909Validator.test_large_integer_multiple_of_integer_valued_float jsonschema.tests.test_validators.TestDraft202012Validator.test_large_integer_multiple_of_integer_valued_float
  • uv run python -m unittest jsonschema.tests.test_validators

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.

Instance validates if multipleOf is an integer, but fails if it's a float

2 participants