-
-
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
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 == 1 Will add some docs now |
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.
Looking good, please update history and docs.
a.py
Outdated
@@ -0,0 +1,20 @@ | |||
import pydantic |
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.
remove this file please.
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. |
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.
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>
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.
Best to run tests before you commit to avoid simple problems like this.
HISTORY.rst
Outdated
@@ -3,9 +3,13 @@ | |||
History | |||
------- | |||
|
|||
v0.28 (unreleased) | |||
.................. | |||
* support ``__post_init_post_parse__`` support to dataclasses, #567 by @sevaho |
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.
typo
pydantic/dataclasses.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.rst
has been updated#<number>
@<whomever>