Skip to content

Support numeric constraints for Decimal types#692

Closed
cocorigon wants to merge 2 commits intojcrist:mainfrom
cocorigon:feat/decimal_constraints
Closed

Support numeric constraints for Decimal types#692
cocorigon wants to merge 2 commits intojcrist:mainfrom
cocorigon:feat/decimal_constraints

Conversation

@cocorigon
Copy link
Copy Markdown

This is my first time playing around with C, so please feel free to tell me if more micro-optimizations can be achieved. Same for compiler hints, notably for the MS_INLINE and MS_NOINLINE near ms_check_decimal_constraints(...): I implemented it in a manner similar to what was done for floats for example, though I must admit that I did not quite understand the pattern for when to use each.

Also, I added a DevContainer for easier setup for newcomers to the project.

Closes #683.

@Siyet
Copy link
Copy Markdown
Collaborator

Siyet commented Mar 31, 2026

Hi @cocorigon! I've run into the same issue (#683) in production - Annotated[Decimal, Meta(gt=0)] raises TypeError when used with schema_components.

Are you still planning to rebase this PR and continue working on it? If not, I'd be happy to pick it up - would open a fresh PR based on your approach, with credit of course.

No rush, just want to make sure the effort isn't duplicated.

@cocorigon
Copy link
Copy Markdown
Author

Hey @Siyet! I don't really do much Python anymore, so no, I will not work on this PR again in the near future.

So feel free to use this code as you wish!

@Siyet
Copy link
Copy Markdown
Collaborator

Siyet commented Apr 10, 2026

Hi @cocorigon, thanks again for the original work here and for the explicit handover note above.

I've picked this up in #1006, which builds on the same approach (C-level constraint check, multiple_of via Decimal arithmetic) and is rebased against the current src/msgspec/ + tests/unit/ layout. Closing this one as superseded so review attention can stay on a single thread. Credit to you is in the #1006 description.

Closes #683 will move to #1006.

@Siyet Siyet closed this Apr 10, 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.

Support numeric constraints for Decimal values

2 participants