-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix resolution of forward refs in dataclass base classes that are not present in the subclass module namespace #8751
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
Conversation
… present in the subclass module namespace
CodSpeed Performance ReportMerging #8751 will not alter performanceComparing Summary
|
|
The only job failing on CI is the tags check, so please review |
alexmojaki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this looks promising!
|
All comments have been addressed, please review (looks like hooky doesn't react to rereview requests). |
alexmojaki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks!
|
@alexmojaki Just to check, is there anything else I need to do to get this merged? |
|
I've tested out using swapped orders for traversing the MROs, and I think the current approach makes sense. There were test failures for all other options re MRO traversal @dmontagu |
…ons in base classes Fix was pydantic/pydantic#8751
…ons in base classes Fix was pydantic/pydantic#8751
…ons in base classes Fix was pydantic/pydantic#8751
Change Summary
(Text mostly copied from #8730) When the base class of a dataclass has an annotation type that is not imported by the module the subclass is in, and
from __future__ import annotationsis in use (or in my case, Cython is in use), an error occurs.The root cause is that when pydantic builds up the type namespace, it does not consider base classes (https://github.com/pydantic/pydantic/blob/main/pydantic/_internal/_generate_schema.py#L1474). This is fine for models, because each base class builds a schema immediately, but does not work for plain stdlib dataclasses. This PR adds code to iterate though all of the base classes of the dataclass that are also dataclasses, and push their namespaces as well, which should cover all of the fields which Pydantic will attempt to resolve.
Related issue number
Fixes #8730
Checklist
Selected Reviewer: @alexmojaki