Fix various issues with dataclasses and use_attribute_docstrings#11246
Merged
Fix various issues with dataclasses and use_attribute_docstrings#11246
use_attribute_docstrings#11246Conversation
Deploying pydantic-docs with
|
| Latest commit: |
dbc6825
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://425a87be.pydantic-docs.pages.dev |
| Branch Preview URL: | https://dataclasses-fixes.pydantic-docs.pages.dev |
CodSpeed Performance ReportMerging #11246 will improve performances by 10.84%Comparing Summary
Benchmarks breakdown
|
3934346 to
40c7c32
Compare
Contributor
Contributor
sydney-runkle
left a comment
There was a problem hiding this comment.
Nice work overall, left a few comments / questions. Thanks!
Comment on lines
+67
to
+71
| def _update_fields_from_docstrings(cls: type[Any], fields: dict[str, FieldInfo], use_inspect: bool = False) -> None: | ||
| fields_docs = extract_docstrings_from_cls(cls, use_inspect=use_inspect) | ||
| for ann_name, field_info in fields.items(): | ||
| if field_info.description is None and ann_name in fields_docs: | ||
| field_info.description = fields_docs[ann_name] |
Contributor
There was a problem hiding this comment.
Re letting callers decide if this is necessary - I assume this is for general cleanliness and to avoid the overhead of a function call if not necessary?
…in the process of being built Do not rely on `__pydantic_validator__`, an attribute which is set only when the class is fully built. Because we check for this condition during schema building, we end up considering the class as a stdlib dataclass. As a consequence, the deepcopy logic of `FieldInfo` instances was tweaked, as in some tests, the deep copy would fail. Instead, make a shallow copy of every `FieldInfo` instance, this is enough (the same thing is done in `collect_model_fields` for Pydantic models, we make a shallow copy of the parent fields).
Let callers be responsible for checking if using docstrings is necessary.
40c7c32 to
548348c
Compare
548348c to
dbc6825
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
Fixes #11243.
Edit post 2.11 release: fixes #11133.
Best reviewed commit per commit.
Related issue number
Checklist