mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
2a04aa76b0
* added feature post_init_post_parse * fixed bug where post_init_post_parse was triggered without looking is post_init_original is set * change double to single quotes * __doc__ strings fixed back to double quote * added better way of doing the post_init_post_parse also tests passes now * removed unused file * deleted unnecessary test * update history.rst, changed previouis change 560 to breaking change because it broke the original flow * update docs, added section post_init_post_parse under dataclasses * added __post_init_post_parse__ as attribute of DataclassType * Update HISTORY.rst Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Update HISTORY.rst Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Update pydantic/dataclasses.py Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * update docs, added subsection initialize hooks under dataclasses * my bad * make tests work again * removed checking if post_init_parse is none * correct typo in history * fixed typo in history.rst
25 lines
464 B
Python
25 lines
464 B
Python
from datetime import datetime
|
|
from pydantic.dataclasses import dataclass
|
|
|
|
@dataclass
|
|
class Birth:
|
|
year: int
|
|
month: int
|
|
day: int
|
|
|
|
|
|
@dataclass
|
|
class User:
|
|
birth: Birth
|
|
|
|
def __post_init__(self):
|
|
print(self.birth)
|
|
# > {'year': 1995, 'month': 3, 'day': 2}
|
|
|
|
def __post_init_post_parse__(self):
|
|
print(self.birth)
|
|
# > Birth(year=1995, month=3, day=2)
|
|
|
|
|
|
user = User(**{'birth': {'year': 1995, 'month': 3, 'day': 2}})
|