FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

✨ Add support for decimal-specific configs in `Field()` by tiangolo · Pull Request #3507 · pydantic/pydantic · GitHub

Repository navigation

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

Merged
samuelcolvin merged 4 commits into
pydantic:masterfrom
tiangolo:field-condecimal
Dec 11, 2021
Merged

samuelcolvin merged 4 commits into
pydantic:masterfrom
tiangolo:field-condecimal

Conversation

tiangolo commented Dec 10, 2021 •
edited
Loading

Copy link
Copy Markdown
Contributor

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:

And the autocompletion for the new alternative:

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

Copy link
Copy Markdown
Contributor Author

please review

Copy link
Copy Markdown
Member

great, thank you so much.

productdevbook commented Dec 31, 2021 •
edited
Loading

Copy link
Copy Markdown

how to fixed type ?

0.0.6v used

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL