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

feat: pass config to NamedTuple fields #4225

Merged
merged 3 commits into from Aug 8, 2022

Conversation

rorybyrne
Copy link
Contributor

Change Summary

This PR changes the way pydantic validates NamedTuple fields. Currently, a new vanilla BaseModel is created dynamically for the field, and used for validation. This PR simply passes the parent model's Config to that newly created model, allowing settings like allow_arbitrary_types to be propagated to the attributes of NamedTuple fields.

Related issue number

fix #4219

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

@rorybyrne
Copy link
Contributor Author

please review

Copy link
Member

@PrettyWood PrettyWood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks good catch! Passing the config to TypedDict has been added recently. We should have done it for NamedTuple at the same time

@rorybyrne
Copy link
Contributor Author

Sweet, thanks for the quick review ❤️

@hramezani
Copy link
Member

hramezani commented Jul 11, 2022

@synek Thanks for your patch 👍

@hramezani
Copy link
Member

Please update

@rorybyrne
Copy link
Contributor Author

Thanks for the review @hramezani. Do you need any other changes, or is the PR ready?

@hramezani
Copy link
Member

Thanks for the review @hramezani. Do you need any other changes, or is the PR ready?

No, we actually waiting for @samuelcolvin for final review

@samuelcolvin samuelcolvin merged commit f6c74a5 into pydantic:master Aug 8, 2022
@samuelcolvin
Copy link
Member

thanks so much.

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.

arbitrary_types_allowed does not propagate to the model which is created for a NamedTuple
4 participants