-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: use dataclasses proxy for frozen or empty dataclasses #4878
fix: use dataclasses proxy for frozen or empty dataclasses #4878
Conversation
@@ -197,7 +189,15 @@ def dataclass( | |||
def wrap(cls: Type[Any]) -> 'DataclassClassOrWrapper': | |||
import dataclasses | |||
|
|||
if is_builtin_dataclass(cls) and _extra_dc_args(_cls) == _extra_dc_args(_cls.__bases__[0]): # type: ignore | |||
should_use_proxy = ( |
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.
I reckon I should have added directly the dataclass kwarg use_proxy
and invite people to write
PydanticDC = pydantic.dataclasses.dataclass(DC, use_proxy=True)
to keep DC
untouched.
It would have been explicit for these rare use cases and would have avoided this kind of (very weak) magic
But I reckon it's too late now for v1 and v2 won't need this at all yay 🎉
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.
you're probably right, but hindsight is a beautiful thing. No worries now.
7d8a168
to
1a3ae7b
Compare
72217a2
to
43892c3
Compare
Please review |
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.
LGTM!
This looks great, really pleased you were able to fix it so easily, I wasn't sure where to go.
Just one small suggestion, otherwise this is good to go.
Please update.
@@ -183,7 +170,7 @@ def dataclass( | |||
unsafe_hash: bool = False, | |||
frozen: bool = False, | |||
config: Union[ConfigDict, Type[object], None] = None, | |||
validate_on_init: Optional[bool] = None, | |||
use_proxy: Optional[bool] = None, |
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.
should we allow the validate_on_init
and raise a deprecation warning here?
Otherwise this is technically a breaking change.
@@ -197,7 +189,15 @@ def dataclass( | |||
def wrap(cls: Type[Any]) -> 'DataclassClassOrWrapper': | |||
import dataclasses | |||
|
|||
if is_builtin_dataclass(cls) and _extra_dc_args(_cls) == _extra_dc_args(_cls.__bases__[0]): # type: ignore | |||
should_use_proxy = ( |
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.
you're probably right, but hindsight is a beautiful thing. No worries now.
please review |
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.
LGTM.
Anyone else have any inputs quickly? Otherwise let's merge and get v1.10.3 released.
please review |
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!
thanks so much. |
fix #4498
fix #4565
fix #4877
fix #4585