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

[Trixie] Pydantic v2 #2005

Draft
wants to merge 59 commits into
base: trixie
Choose a base branch
from
Draft

[Trixie] Pydantic v2 #2005

wants to merge 59 commits into from

Conversation

Axolotle
Copy link
Member

@Axolotle Axolotle commented Dec 3, 2024

Solution

Use new features of pydantic v2 to improve type coercing/validation.

Constraints:
Now use custom "validators" (constraints) that can be used directly in type definition but also as dynamic annotation.
Changed the way Option's annotation is built with those constraints

Option's normalize and humanize now properly validate passed values and serialize it depending on modes:

  • "string", for bash scripts which is the mode used in normalize for now but will next be called in a new method stringify
  • "human", called in humanize to display human readable values
  • Another mode will be implemented at some point: "normal" which will be traditional python types and will be the serializing mode of normalized
    Those modes are also available to serialize a full form (normal mode will be used to serialize non app config panels settings)

None:
Harmonized "none" values for every type, (None, "", "none", "_none") (and uppercase) are treated as None and serialized depending on type.

New attributes: multiple
Options can now use multiple: true to accept a list of values, it will properly parse coma list string like F1,F2,F3 as lists then will perform validation on each item. So you can use multiple: true on type: string with a custom pattern that will be used on all list items. All option types can be multiple except password|file.
Added some new tests with this attr.

Removed call to xfail/xpass in tests and fixed remaining parsing/validation errors

PR Status

WIP

TODO

  • [] reflect changes on web admin
  • check/clean/add i18n errors keys
  • implement mode normal

How to test

Yes

@alexAubin alexAubin changed the title Enh: pydantic v2 [Trixie] Pydantic v2 Dec 13, 2024
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.

2 participants