added feature post_init_post_parse#567
Conversation
|
Looking good, needs tests and docs. |
… post_init_original is set
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
==========================================
- Coverage 100% 99.91% -0.09%
==========================================
Files 15 15
Lines 2491 2497 +6
Branches 497 499 +2
==========================================
+ Hits 2491 2495 +4
- Misses 0 1 +1
- Partials 0 1 +1 |
|
I don't understand why tests fail tho, if I install it locally it works :/ |
|
please revert to single quotes, then I'll review. |
|
Sorry, autoformatter on save ;) |
|
Yeah you were right hasattr is not the way to go ;) Also added a test which shows the difference between post_init and post_init_post_parse: def test_post_init_post_parse_types():
@pydantic.dataclasses.dataclass
class CustomType(object):
b: int
@pydantic.dataclasses.dataclass
class MyDataclass:
a: CustomType
def __post_init__(self):
assert type(self.a) == dict
def __post_init_post_parse__(self):
assert type(self.a) == CustomType
d = MyDataclass(**{"a": {"b": 1}})
assert d.a.b == 1Will add some docs now |
samuelcolvin
left a comment
There was a problem hiding this comment.
Looking good, please update history and docs.
| @@ -0,0 +1,20 @@ | |||
| import pydantic | |||
|
Added docs and update history. I think this should be in a new version because it is a new feature? If not I update the version back to 0.27 and it my update to history to 0.27 aswell. |
samuelcolvin
left a comment
There was a problem hiding this comment.
just a few small things, otherwise looking good.
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 2491 2495 +4
Branches 497 498 +1
=====================================
+ Hits 2491 2495 +4 |
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
samuelcolvin
left a comment
There was a problem hiding this comment.
Best to run tests before you commit to avoid simple problems like this.
|
|
||
| v0.28 (unreleased) | ||
| .................. | ||
| * support ``__post_init_post_parse__`` support to dataclasses, #567 by @sevaho |
| post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None) | ||
| if post_init_original and post_init_original.__name__ == '_pydantic_post_init': | ||
| post_init_original = None | ||
| if post_init_post_parse: |
There was a problem hiding this comment.
this is wrong, it needs to be removed completely, I guess this is why tests are failing.
|
Idd it had no use |
|
great, thanks. |
* fix: copy with tzinfo * fix: apply feedback
Change Summary
Now you can have
__post_init_post_parse__that runs after pydantic has validated the input.So
__init__()->__post_init__()-> pydantic object validation ->__post_init_post_parse__()Related issue number
#566
Checklist
HISTORY.rsthas been updated#<number>@<whomever>