8000 ✨ Add support for decimal-specific configs in `Field()` by tiangolo · Pull Request #3507 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@tiangolo
Copy link
Contributor
@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
Contributor 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.

4 participants

0