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: stdlib dataclass converted into pydantic dataclass still equal its stdlib dataclass equivalent #2182
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2182 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 4121 4125 +4
Branches 829 830 +1
=========================================
+ Hits 4121 4125 +4
Continue to review full report at Codecov.
|
…its stdlib dataclass equivalent closes pydantic#2162
1088096
to
a949c0a
Compare
Humm, my only reservation is that standard python dataclasses to clever stuff so that different dataclasses with the same fields (and values) are not equal: from dataclasses import dataclass
@dataclass(frozen=True)
class Foo:
a: int
b: float
@dataclass(frozen=True)
class Bar:
a: int
b: float
f = Foo(a=10, b=1.0)
b = Bar(a=10, b=1.0)
debug(f == b) #> False
f2 = Foo(a=10, b=1.0)
debug(f == f2) #> True Isn't there a risk that different dataclasses incorrectly being equal is worse than them incorrectly being unequal? I know "correct" and "incorrect" are subjective here and some might argue (very reasonably) that If we can't reliably match python's standard behaviour, I'd be happy to just raise an error some people don't assume stuff will work which won't. |
I think it shouldn't be that hard to copy python's own logic more or less verabim: |
I agree that copying Python's own logic is a good idea, but how would you handle the class equality check? Read below for details. Near the end of that code, Python calls @samuelcolvin Do you think that replacing the class equality check with something like |
Yes, I think makes sense. |
FYI I thought again about all the issues related to stdlib dataclass to validated dataclass |
Will be tackled in #2557 |
Change Summary
Related issue number
closes #2162
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)