Skip to content

🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field - #1730

Open
YuriiMotov wants to merge 4 commits into
mainfrom
gt-ge-lt-le-type-hints
Open

🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field#1730
YuriiMotov wants to merge 4 commits into
mainfrom
gt-ge-lt-le-type-hints

Conversation

@YuriiMotov

Copy link
Copy Markdown
Member

This PR updates type hints for gt, ge, lt, le parameters of Field to be in line with Pydantic's version:

    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,

Also, added some tests for these parameters


You can currently use parameters like gt, ge, etc.. for types of fields other than int \ float:

from pydantic import ValidationError
from sqlmodel import Field, SQLModel


class Model(SQLModel):
    int_value: int = Field(gt=10)
    tuple_value: tuple[int, int] = Field(gt=(1, 2))


Model(int_value=11, tuple_value=(1, 3))

try:
    Model(int_value=10, tuple_value=(1, 3))
except ValidationError as exc_info:
    print(exc_info)

#     1 validation error for Model
# int_value
#   Input should be greater than 10 [type=greater_than, input_value=10, input_type=int]
#     For further information visit https://errors.pydantic.dev/2.12/v/greater_than


try:
    Model(int_value=11, tuple_value=(1, 2))
except ValidationError as exc_info:
    print(exc_info)

# 1 validation error for Model
# tuple_value
#   Input should be greater than (1, 2) [type=greater_than, input_value=(1, 2), input_type=tuple]
#     For further information visit https://errors.pydantic.dev/2.12/v/greater_than

... but mypy will argue:

error: No overload variant of "Field" matches argument type "tuple[int, int]"  [call-overload]

This PR fixes this

@YuriiMotov YuriiMotov added the feature New feature or request label Jan 29, 2026
@YuriiMotov YuriiMotov changed the title ✨ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field 🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field Jan 29, 2026
@YuriiMotov
YuriiMotov marked this pull request as ready for review January 29, 2026 10:44
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026
@github-actions

This comment was marked as resolved.

@github-actions github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026
@github-actions github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Aug 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

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

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants