8000 Recommend against using `Ellipsis` (`...`) with `Field` by Viicos · Pull Request #10661 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Viicos
Copy link
Member
@Viicos Viicos commented Oct 18, 2024

Also fix a bug where under certain scenarios, a Field function inside Annotated metadata would retain the Ellipsis as a default value.

Also make PrivateAttr on par with Field and the special casing of Ellipsis.

Change Summary

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Oct 18, 2024
#> [('a',), ('b',), ('c',), ('d',), ('e',)]
```

## Required fields
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the updated documentation, the rest is just switching from Field(...) to Field()

@cloudflare-workers-and-pages
Copy link
cloudflare-workers-and-pages bot commented Oct 18, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 76cc978
Status: ✅  Deploy successful!
Preview URL: https://8f7cad7a.pydantic-docs.pages.dev
Branch Preview URL: https://field-ellipsis.pydantic-docs.pages.dev

View logs

Comment on lines +212 to +215
# Also remove it from the attributes set, otherwise
# `GenerateSchema._common_field_schema` mistakenly
# uses it:
self._attributes_set.pop('default', None)
Copy link
Member Author

Choose a reason for hiding this comment

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

See the added test for an example

for definition in adapter.core_schema['definitions']:
if definition['schema']['model_name'] in ['NestedState', 'LoopState']:
assert definition['schema']['fields']['substate']['schema']['schema']['type'] == 'tagged-union'
assert definition['schema']['fields']['substate']['schema']['type'] == 'tagged-union'
Copy link
Member Author
@Viicos Viicos Oct 18, 2024

Choose a reason for hiding this comment

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

As a consequence of the fixed bug: a slight change in schemas because AnyState is no longer considered to have a default value of ....

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining. I'm surprised this changed the schema - I guess there was a with_default schema here previously?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes exactly

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a bug fix.

@codspeed-hq
Copy link
codspeed-hq bot commented Oct 18, 2024

CodSpeed Performance Report

Merging #10661 will not alter performance

Comparing field-ellipsis (76cc978) with main (220b2f6)

Summary

✅ 44 untouched benchmarks

@github-actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  fields.py
Project Total  

This report was generated by python-coverage-comment-action

Copy link
Contributor
@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Nice. One quick question, but looks great.

Surprised re how many places we used this in the docs / examples. Nice job with the update!

for definition in adapter.core_schema['definitions']:
if definition['schema']['model_name'] in ['NestedState', 'LoopState']:
assert definition['schema']['fields']['substate']['schema']['schema']['type'] == 'tagged-union'
assert definition['schema']['fields']['substate']['schema']['type'] == 'tagged-union'
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for explaining. I'm surprised this changed the schema - I guess there was a with_default schema here previously?

Also fix a bug where under certain scenarios, a `Field` function
inside `Annotated` metadata would retain the `Ellipsis` as a
default value.

Also make `PrivateAttr` on par with `Field` and the special casing
of `Ellipsis`.
@Viicos Viicos merged commit a1ffc82 into main Oct 21, 2024
@Viicos Viicos deleted the field-ellipsis branch October 21, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotes-fix Used for bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0