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

Improve pydantic model default and alias handling #378

Merged
merged 3 commits into from
Mar 23, 2023
Merged

Improve pydantic model default and alias handling #378

merged 3 commits into from
Mar 23, 2023

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented Mar 8, 2023

Proposed Changes

Improve default and alias handling.

  • Make Optional[...] defaults explicits. This will be required in pydantic v2 anyway.
  • Use named argument for Field.default to be better compatible with PEP 681.
  • Remove unnecessary Field(...) defaults for required fields.
  • Add pydantic.mypy plugin to handle aliases and Config.allow_population_by_field_name = True correctly.
  • Update example to use field name if allow_population_by_field_name = True.

Note
The pydantic mypy plugin doesn't work for 1.1.1 just yet. There is an open PR to fix it.

Once the plugin is fixed and pydantic is updated all current mypy errors will be resolved.

Edit

Related Issues

pydantic/pydantic#5111

@frenck frenck added the enhancement Enhancement of the code, not introducing new features. label Mar 23, 2023
@frenck frenck merged commit 4e01112 into frenck:main Mar 23, 2023
@frenck
Copy link
Owner

frenck commented Mar 23, 2023

Thanks, @cdce8p 👍

@cdce8p cdce8p deleted the field-defaults branch March 23, 2023 19:57
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enhancement of the code, not introducing new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants