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

Reflect namedtuple default values during validation #7144

Merged
merged 1 commit into from Aug 16, 2023

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Aug 16, 2023

Closes #7134

Selected Reviewer: @hramezani

@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 201f6cf
Status: ✅  Deploy successful!
Preview URL: https://7f6e1533.pydantic-docs2.pages.dev
Branch Preview URL: https://dmontagu-namedtuple-defaults.pydantic-docs2.pages.dev

View logs

@dmontagu
Copy link
Contributor Author

please review

@@ -1130,7 +1130,9 @@ def _namedtuple_schema(self, namedtuple_cls: Any, origin: Any) -> core_schema.Co

arguments_schema = core_schema.arguments_schema(
[
self._generate_parameter_schema(field_name, annotation)
self._generate_parameter_schema(
field_name, annotation, default=namedtuple_cls._field_defaults.get(field_name, Parameter.empty)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though this looks like a private attribute access, this _field_defaults attribute is explicitly present in the type stubs for NamedTuple — I think it's intended for public access, just has an underscore to prevent name collisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@Viicos Viicos Aug 16, 2023

Choose a reason for hiding this comment

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

@dmontagu dmontagu merged commit 37b7f08 into main Aug 16, 2023
49 checks passed
@dmontagu dmontagu deleted the dmontagu/namedtuple-defaults branch August 16, 2023 20:05
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.

NamedTuple default values are ignored in validation
4 participants