-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
refactor: change pydantic dataclass decorator #2557
refactor: change pydantic dataclass decorator #2557
Conversation
f0b6777
to
2f82543
Compare
Looks interesting, why |
c97fd82
to
feeee81
Compare
0acde5b
to
374f2df
Compare
@samuelcolvin I added So I'm pretty happy with the current state of this PR The chosen behaviour is import dataclasses
import pydantic
@pydantic.dataclasses.dataclass
class M1:
x: int
@pydantic.dataclasses.dataclass
@dataclasses.dataclass
class M2:
x: int
@dataclasses.dataclass
class M3:
x: int
VM3 = pydantic.dataclasses.dataclass(M3)
assert M1(x='3').x == 3
assert M2(x='3').x == 3
assert M3(x='3').x == '3'
assert VM3(x='3').x == 3
assert M3(x=3) == VM3(x=3) The only issue is for the 3rd case, which should be quite rare! For python 3.6 we hence tolerate a degraded behaviour with a side effect on the stdlib dataclass: it now triggers validation by default. But it can be changed directly in the validator on thanks to a magic kwarg in @samuelcolvin I wait for your remarks before updating the documentation. It's quite heavy sorry for that! |
374f2df
to
e1396e4
Compare
@PrettyWood another testcase to add to your branch #2594 |
when using from pydantic import Extra
from pydantic.dataclasses import dataclass
class Config:
extra = Extra.allow
@dataclass(config=Config)
class Foo:
a: int
foo = Foo(a=1, b=2)
print(foo.b) # 2
print(foo) # Foo(a=1) |
@DetachHead This caveat is documented in 5907f82 |
is there an issue tracking it? if not i can make one |
Can we please merge this and cut a release? :) |
@samuelcolvin @ahirner @robons any update on this? |
Sorry, been busy with pydantic-core, I'll work on 1.10 soon and this will be included. @PrettyWood what do you think? |
@samuelcolvin taking some days off after a very busy Q2! If you can resolve conflicts, I reckon it's solving a lot of issues with dataclasses. And we'll probably have cleaner logic (and hence code) in v2 |
|
Thank you so much @PrettyWood 🎉, closing 10 issues with one PR must be a record. Sorry everyone for the delay on this. |
ValidatedItem(name='qwe', b=b'1', pydantic_run_validation=False). using pydantic_run_validation doesn't seems to skip validation. I am using pydantic -1.10.2 @samuelcolvin @PrettyWood I have created a issue for this - #4496 |
Change Summary
Now this is doable
Related issue number
A bunch on stdlib dataclass to validated dataclass
closes #2162
closes #2383
closes #2398
closes #2424
closes #2541
closes #2555
closes #2594
closes #2511
closes #3011
closes #3046
closes #3109
closes #3162
closes #3709
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)