Open
Conversation
Collaborator
|
It looks like the Git history needs to be fixed on this one. |
Collaborator
Author
Extends gt, ge, lt, le, and multiple_of Meta constraints to work with decimal.Decimal types, enabling exact arithmetic comparisons and sub-integer precision constraints without floating point issues. Constraint bounds passed as int or float are coerced to Decimal via their string representation to preserve precision. multiple_of uses Python's % operator for exact arithmetic. Closes #683
8c80626 to
f406983
Compare
Collaborator
Author
|
@ofek done — force-pushed a clean rewrite of the branch:
Build job is still red on the link checker but that's the unrelated #1008 fix; nothing in this branch touches it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reopening #998 (auto-closed when fork was deleted).
Fixes #683.
Previously, the numeric constraints
gt,ge,lt,le, andmultiple_ofinmsgspec.Metawere only valid forintandfloattypes. This PR extends support todecimal.Decimal.PR #692 by @cocorigon has been open since May 2024. The author has since explicitly declined to continue it and invited others to take it over. This is a fresh implementation with documentation and full test coverage.
Changes
_core.c: Added five newTypeNodeconstraint flags backed byPyObject*slots storingDecimalinstances. A newms_check_decimal_constraints()function is called after everyDecimaldecode path.__init__.pyi: UpdatedMeta.__init__parameter types to includeDecimal.docs/constraints.rst: Updated Numeric Constraints section to mentiondecimal.Decimal.tests/unit/test_constraints.py: AddedTestDecimalConstraintscovering all constraint types.Notable design decisions
multiple_offorDecimaluses Python's%operator, which gives exact arithmetic.floatare converted toDecimalvia string representation to preserve precision.