Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for decimal-specific configs in Field() #3507

Merged
merged 4 commits into from Dec 11, 2021

Conversation

tiangolo
Copy link
Member

@tiangolo tiangolo commented Dec 10, 2021

Change Summary

This adds support for Decimal-specific configs, that would only be supported with condecimal(), in Field().

I want this in particular here to then be able to also support it in SQLModel. 🤓

This means that an example like this:

from pydantic import BaseModel, condecimal


class Model(BaseModel):
    decimal_max_digits_and_places: condecimal(max_digits=2, decimal_places=2)

could also be written like this:

from decimal import Decimal
from pydantic import BaseModel, Field


class Model(BaseModel):
    decimal_max_digits_and_places: Decimal = Field(max_digits=2, decimal_places=2)

The main advantage is that editors and tools can provide better support when the type is static and not the return of a function (that works at runtime, but tools struggle with it during static analysis, etc).

E.g. the autocompletion for condecimal:

Selection_007

And the autocompletion for the new alternative:

Selection_008

Related issue number

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@tiangolo
Copy link
Member Author

please review

@samuelcolvin
Copy link
Member

great, thank you so much.

@productdevbook
Copy link

productdevbook commented Dec 31, 2021

CleanShot 2021-12-31 at 08 07 14

how to fixed type ?

0.0.6v used

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.

None yet

4 participants