Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

fix #1451

Leveraged new RangeConstraints plumbing so type aliases and annotations keep the Gt/Ge/Lt/Le metadata

Propagated those constraints into Pydantic field metadata and enforced them for class-body defaults, including support for the previously missing le keyword

Added le handling to Pydantic binding constants plus range merging helpers

@meta-cla meta-cla bot added the cla signed label Nov 3, 2025
@asukaminato0721 asukaminato0721 marked this pull request as ready for review November 3, 2025 07:59
@migeed-z
Copy link
Contributor

migeed-z commented Nov 3, 2025

Thank you for this! this would be a great change to support. I will take a more detailed look soon.
One thing that would be really helpful is to add comments on the helper functions on what they do and how they relate to the overall solution.

Also, would that solution also check the "gt"/"lt" etc. field constraints? if we're adding actual range constraints to the solver then we could also leverage this for the "gt" and "lt" testcases? right now, they do not check ranges. They just check against the annotation.

class Model(BaseModel):
value: int = Field(1, gt=0)
"#,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected this testcase in the same file:

from pydantic import BaseModel, Field
class Model(BaseModel):
   x: int = Field(gt=0, lt=10)

Model(x=5) 
Model(x=0)  
Model(x=15)

to now have a different result. Would that diff not support that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the new logic only kicks in when we analyze class-body defaults.

If we want to catch those call-site violations too, we’d need a larger follow-up that threads the range constraints through the call analysis (so the solver can reject Model(x=0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support types like pydantic.types.PositiveInt

3 participants