prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  __post_init__ is not triggered for descendant dataclass 
  The `__post_init__` method of parent is not called in child classes.
  
  * OS: **Ubuntu**
  * Python version `import sys; print(sys.version)`: **3.7.2 (default, Mar 25 2019, 19:29:53) **
  * Pydantic version `import pydantic; print(pydantic.VERSION)`: **0.32.1**
  
  
  ```py
  from dataclasses import dataclass, field
  from typing import Any
  
  # comment the pydantinc import below to see the expected result
  from pydantic.dataclasses import dataclass
  
  @dataclass
  class Base:
      x: float
      y: float
  
      def __post_init__(self):
          print('Called!')
          self.z = self.x + self.y
  
  @dataclass
  class Child(Base):
      a: int
  
  obj = Child(a=0, x=1.5, y=2.5)
  print(obj.z)
  ```
  
  Everything works fine when using the `dataclass` from standard library. After looking through the code I expected that an easy workaround would be to add simple `__post_init__` in child:
  
  ```python
  @dataclass
  class Child(Base):
      a: int
  
      def __post_init__(self):
          super().__post_init__()
  ```
  
  Now I do get 'Called!' message, but the 'z' attribute is not preserved anyway...
  
  Do I miss something obvious in the usage of pydantic?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pydantic/dataclasses.py`
  Content:
  ```
  1 import dataclasses
  2 from typing import TYPE_CHECKING, Any, Callable, Dict, Generator, Optional, Type, Union
  3 
  4 from .class_validators import gather_validators
  5 from .error_wrappers import ValidationError
  6 from .errors import DataclassTypeError
  7 from .fields import Required
  8 from .main import create_model, validate_model
  9 from .utils import AnyType
  10 
  11 if TYPE_CHECKING:  # pragma: no cover
  12     from .main import BaseConfig, BaseModel  # noqa: F401
  13 
  14     class DataclassType:
  15         __pydantic_model__: Type[BaseModel]
  16         __initialised__: bool
  17 
  18         def __init__(self, *args: Any, **kwargs: Any) -> None:
  19             pass
  20 
  21         @classmethod
  22         def __validate__(cls, v: Any) -> 'DataclassType':
  23             pass
  24 
  25 
  26 def _validate_dataclass(cls: Type['DataclassType'], v: Any) -> 'DataclassType':
  27     if isinstance(v, cls):
  28         return v
  29     elif isinstance(v, (list, tuple)):
  30         return cls(*v)
  31     elif isinstance(v, dict):
  32         return cls(**v)
  33     else:
  34         raise DataclassTypeError(class_name=cls.__name__)
  35 
  36 
  37 def _get_validators(cls: Type['DataclassType']) -> Generator[Any, None, None]:
  38     yield cls.__validate__
  39 
  40 
  41 def setattr_validate_assignment(self: 'DataclassType', name: str, value: Any) -> None:
  42     if self.__initialised__:
  43         d = dict(self.__dict__)
  44         d.pop(name, None)
  45         known_field = self.__pydantic_model__.__fields__.get(name, None)
  46         if known_field:
  47             value, error_ = known_field.validate(value, d, loc=name, cls=self.__class__)
  48             if error_:
  49                 raise ValidationError([error_], type(self))
  50 
  51     object.__setattr__(self, name, value)
  52 
  53 
  54 def _process_class(
  55     _cls: AnyType,
  56     init: bool,
  57     repr: bool,
  58     eq: bool,
  59     order: bool,
  60     unsafe_hash: bool,
  61     frozen: bool,
  62     config: Type['BaseConfig'],
  63 ) -> 'DataclassType':
  64     post_init_original = getattr(_cls, '__post_init__', None)
  65     post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)
  66     if post_init_original and post_init_original.__name__ == '_pydantic_post_init':
  67         post_init_original = None
  68 
  69     def _pydantic_post_init(self: 'DataclassType', *initvars: Any) -> None:
  70         if post_init_original is not None:
  71             post_init_original(self, *initvars)
  72         d = validate_model(self.__pydantic_model__, self.__dict__, cls=self.__class__)[0]
  73         object.__setattr__(self, '__dict__', d)
  74         object.__setattr__(self, '__initialised__', True)
  75         if post_init_post_parse is not None:
  76             post_init_post_parse(self)
  77 
  78     _cls.__post_init__ = _pydantic_post_init
  79     cls = dataclasses._process_class(_cls, init, repr, eq, order, unsafe_hash, frozen)  # type: ignore
  80 
  81     fields: Dict[str, Any] = {
  82         field.name: (field.type, field.default if field.default != dataclasses.MISSING else Required)
  83         for field in dataclasses.fields(cls)
  84     }
  85 
  86     validators = gather_validators(cls)
  87     cls.__pydantic_model__ = create_model(
  88         cls.__name__, __config__=config, __module__=_cls.__module__, __validators__=validators, **fields
  89     )
  90 
  91     cls.__initialised__ = False
  92     cls.__validate__ = classmethod(_validate_dataclass)
  93     cls.__get_validators__ = classmethod(_get_validators)
  94 
  95     if cls.__pydantic_model__.__config__.validate_assignment and not frozen:
  96         cls.__setattr__ = setattr_validate_assignment
  97 
  98     return cls
  99 
  100 
  101 if TYPE_CHECKING:  # pragma: no cover
  102     # see https://github.com/python/mypy/issues/6239 for explanation of why we do this
  103     from dataclasses import dataclass
  104 else:
  105 
  106     def dataclass(
  107         _cls: Optional[AnyType] = None,
  108         *,
  109         init: bool = True,
  110         repr: bool = True,
  111         eq: bool = True,
  112         order: bool = False,
  113         unsafe_hash: bool = False,
  114         frozen: bool = False,
  115         config: Type['BaseConfig'] = None,
  116     ) -> Union[Callable[[AnyType], 'DataclassType'], 'DataclassType']:
  117         """
  118         Like the python standard lib dataclasses but with type validation.
  119 
  120         Arguments are the same as for standard dataclasses, except for validate_assignment which has the same meaning
  121         as Config.validate_assignment.
  122         """
  123 
  124         def wrap(cls: AnyType) -> 'DataclassType':
  125             return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, config)
  126 
  127         if _cls is None:
  128             return wrap
  129 
  130         return wrap(_cls)
  131
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pydantic/dataclasses.py b/pydantic/dataclasses.py
  --- a/pydantic/dataclasses.py
  +++ b/pydantic/dataclasses.py
  @@ -62,9 +62,12 @@
       config: Type['BaseConfig'],
   ) -> 'DataclassType':
       post_init_original = getattr(_cls, '__post_init__', None)
  -    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 not post_init_original:
  +        post_init_original = getattr(_cls, '__post_init_original__', None)
  +
  +    post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)
   
       def _pydantic_post_init(self: 'DataclassType', *initvars: Any) -> None:
           if post_init_original is not None:
  @@ -91,6 +94,8 @@
       cls.__initialised__ = False
       cls.__validate__ = classmethod(_validate_dataclass)
       cls.__get_validators__ = classmethod(_get_validators)
  +    if post_init_original:
  +        cls.__post_init_original__ = post_init_original
   
       if cls.__pydantic_model__.__config__.validate_assignment and not frozen:
           cls.__setattr__ = setattr_validate_assignment
  
verification_info: {"golden_diff": "diff --git a/pydantic/dataclasses.py b/pydantic/dataclasses.py\n--- a/pydantic/dataclasses.py\n+++ b/pydantic/dataclasses.py\n@@ -62,9 +62,12 @@\n     config: Type['BaseConfig'],\n ) -> 'DataclassType':\n     post_init_original = getattr(_cls, '__post_init__', None)\n-    post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)\n     if post_init_original and post_init_original.__name__ == '_pydantic_post_init':\n         post_init_original = None\n+    if not post_init_original:\n+        post_init_original = getattr(_cls, '__post_init_original__', None)\n+\n+    post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)\n \n     def _pydantic_post_init(self: 'DataclassType', *initvars: Any) -> None:\n         if post_init_original is not None:\n@@ -91,6 +94,8 @@\n     cls.__initialised__ = False\n     cls.__validate__ = classmethod(_validate_dataclass)\n     cls.__get_validators__ = classmethod(_get_validators)\n+    if post_init_original:\n+        cls.__post_init_original__ = post_init_original\n \n     if cls.__pydantic_model__.__config__.validate_assignment and not frozen:\n         cls.__setattr__ = setattr_validate_assignment\n", "issue": "__post_init__ is not triggered for descendant dataclass \nThe `__post_init__` method of parent is not called in child classes.\r\n\r\n* OS: **Ubuntu**\r\n* Python version `import sys; print(sys.version)`: **3.7.2 (default, Mar 25 2019, 19:29:53) **\r\n* Pydantic version `import pydantic; print(pydantic.VERSION)`: **0.32.1**\r\n\r\n\r\n```py\r\nfrom dataclasses import dataclass, field\r\nfrom typing import Any\r\n\r\n# comment the pydantinc import below to see the expected result\r\nfrom pydantic.dataclasses import dataclass\r\n\r\n@dataclass\r\nclass Base:\r\n    x: float\r\n    y: float\r\n\r\n    def __post_init__(self):\r\n        print('Called!')\r\n        self.z = self.x + self.y\r\n\r\n@dataclass\r\nclass Child(Base):\r\n    a: int\r\n\r\nobj = Child(a=0, x=1.5, y=2.5)\r\nprint(obj.z)\r\n```\r\n\r\nEverything works fine when using the `dataclass` from standard library. After looking through the code I expected that an easy workaround would be to add simple `__post_init__` in child:\r\n\r\n```python\r\n@dataclass\r\nclass Child(Base):\r\n    a: int\r\n\r\n    def __post_init__(self):\r\n        super().__post_init__()\r\n```\r\n\r\nNow I do get 'Called!' message, but the 'z' attribute is not preserved anyway...\r\n\r\nDo I miss something obvious in the usage of pydantic?\n", "before_files": [{"content": "import dataclasses\nfrom typing import TYPE_CHECKING, Any, Callable, Dict, Generator, Optional, Type, Union\n\nfrom .class_validators import gather_validators\nfrom .error_wrappers import ValidationError\nfrom .errors import DataclassTypeError\nfrom .fields import Required\nfrom .main import create_model, validate_model\nfrom .utils import AnyType\n\nif TYPE_CHECKING:  # pragma: no cover\n    from .main import BaseConfig, BaseModel  # noqa: F401\n\n    class DataclassType:\n        __pydantic_model__: Type[BaseModel]\n        __initialised__: bool\n\n        def __init__(self, *args: Any, **kwargs: Any) -> None:\n            pass\n\n        @classmethod\n        def __validate__(cls, v: Any) -> 'DataclassType':\n            pass\n\n\ndef _validate_dataclass(cls: Type['DataclassType'], v: Any) -> 'DataclassType':\n    if isinstance(v, cls):\n        return v\n    elif isinstance(v, (list, tuple)):\n        return cls(*v)\n    elif isinstance(v, dict):\n        return cls(**v)\n    else:\n        raise DataclassTypeError(class_name=cls.__name__)\n\n\ndef _get_validators(cls: Type['DataclassType']) -> Generator[Any, None, None]:\n    yield cls.__validate__\n\n\ndef setattr_validate_assignment(self: 'DataclassType', name: str, value: Any) -> None:\n    if self.__initialised__:\n        d = dict(self.__dict__)\n        d.pop(name, None)\n        known_field = self.__pydantic_model__.__fields__.get(name, None)\n        if known_field:\n            value, error_ = known_field.validate(value, d, loc=name, cls=self.__class__)\n            if error_:\n                raise ValidationError([error_], type(self))\n\n    object.__setattr__(self, name, value)\n\n\ndef _process_class(\n    _cls: AnyType,\n    init: bool,\n    repr: bool,\n    eq: bool,\n    order: bool,\n    unsafe_hash: bool,\n    frozen: bool,\n    config: Type['BaseConfig'],\n) -> 'DataclassType':\n    post_init_original = getattr(_cls, '__post_init__', None)\n    post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)\n    if post_init_original and post_init_original.__name__ == '_pydantic_post_init':\n        post_init_original = None\n\n    def _pydantic_post_init(self: 'DataclassType', *initvars: Any) -> None:\n        if post_init_original is not None:\n            post_init_original(self, *initvars)\n        d = validate_model(self.__pydantic_model__, self.__dict__, cls=self.__class__)[0]\n        object.__setattr__(self, '__dict__', d)\n        object.__setattr__(self, '__initialised__', True)\n        if post_init_post_parse is not None:\n            post_init_post_parse(self)\n\n    _cls.__post_init__ = _pydantic_post_init\n    cls = dataclasses._process_class(_cls, init, repr, eq, order, unsafe_hash, frozen)  # type: ignore\n\n    fields: Dict[str, Any] = {\n        field.name: (field.type, field.default if field.default != dataclasses.MISSING else Required)\n        for field in dataclasses.fields(cls)\n    }\n\n    validators = gather_validators(cls)\n    cls.__pydantic_model__ = create_model(\n        cls.__name__, __config__=config, __module__=_cls.__module__, __validators__=validators, **fields\n    )\n\n    cls.__initialised__ = False\n    cls.__validate__ = classmethod(_validate_dataclass)\n    cls.__get_validators__ = classmethod(_get_validators)\n\n    if cls.__pydantic_model__.__config__.validate_assignment and not frozen:\n        cls.__setattr__ = setattr_validate_assignment\n\n    return cls\n\n\nif TYPE_CHECKING:  # pragma: no cover\n    # see https://github.com/python/mypy/issues/6239 for explanation of why we do this\n    from dataclasses import dataclass\nelse:\n\n    def dataclass(\n        _cls: Optional[AnyType] = None,\n        *,\n        init: bool = True,\n        repr: bool = True,\n        eq: bool = True,\n        order: bool = False,\n        unsafe_hash: bool = False,\n        frozen: bool = False,\n        config: Type['BaseConfig'] = None,\n    ) -> Union[Callable[[AnyType], 'DataclassType'], 'DataclassType']:\n        \"\"\"\n        Like the python standard lib dataclasses but with type validation.\n\n        Arguments are the same as for standard dataclasses, except for validate_assignment which has the same meaning\n        as Config.validate_assignment.\n        \"\"\"\n\n        def wrap(cls: AnyType) -> 'DataclassType':\n            return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, config)\n\n        if _cls is None:\n            return wrap\n\n        return wrap(_cls)\n", "path": "pydantic/dataclasses.py"}], "after_files": [{"content": "import dataclasses\nfrom typing import TYPE_CHECKING, Any, Callable, Dict, Generator, Optional, Type, Union\n\nfrom .class_validators import gather_validators\nfrom .error_wrappers import ValidationError\nfrom .errors import DataclassTypeError\nfrom .fields import Required\nfrom .main import create_model, validate_model\nfrom .utils import AnyType\n\nif TYPE_CHECKING:  # pragma: no cover\n    from .main import BaseConfig, BaseModel  # noqa: F401\n\n    class DataclassType:\n        __pydantic_model__: Type[BaseModel]\n        __initialised__: bool\n\n        def __init__(self, *args: Any, **kwargs: Any) -> None:\n            pass\n\n        @classmethod\n        def __validate__(cls, v: Any) -> 'DataclassType':\n            pass\n\n\ndef _validate_dataclass(cls: Type['DataclassType'], v: Any) -> 'DataclassType':\n    if isinstance(v, cls):\n        return v\n    elif isinstance(v, (list, tuple)):\n        return cls(*v)\n    elif isinstance(v, dict):\n        return cls(**v)\n    else:\n        raise DataclassTypeError(class_name=cls.__name__)\n\n\ndef _get_validators(cls: Type['DataclassType']) -> Generator[Any, None, None]:\n    yield cls.__validate__\n\n\ndef setattr_validate_assignment(self: 'DataclassType', name: str, value: Any) -> None:\n    if self.__initialised__:\n        d = dict(self.__dict__)\n        d.pop(name, None)\n        known_field = self.__pydantic_model__.__fields__.get(name, None)\n        if known_field:\n            value, error_ = known_field.validate(value, d, loc=name, cls=self.__class__)\n            if error_:\n                raise ValidationError([error_], type(self))\n\n    object.__setattr__(self, name, value)\n\n\ndef _process_class(\n    _cls: AnyType,\n    init: bool,\n    repr: bool,\n    eq: bool,\n    order: bool,\n    unsafe_hash: bool,\n    frozen: bool,\n    config: Type['BaseConfig'],\n) -> 'DataclassType':\n    post_init_original = getattr(_cls, '__post_init__', None)\n    if post_init_original and post_init_original.__name__ == '_pydantic_post_init':\n        post_init_original = None\n    if not post_init_original:\n        post_init_original = getattr(_cls, '__post_init_original__', None)\n\n    post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)\n\n    def _pydantic_post_init(self: 'DataclassType', *initvars: Any) -> None:\n        if post_init_original is not None:\n            post_init_original(self, *initvars)\n        d = validate_model(self.__pydantic_model__, self.__dict__, cls=self.__class__)[0]\n        object.__setattr__(self, '__dict__', d)\n        object.__setattr__(self, '__initialised__', True)\n        if post_init_post_parse is not None:\n            post_init_post_parse(self)\n\n    _cls.__post_init__ = _pydantic_post_init\n    cls = dataclasses._process_class(_cls, init, repr, eq, order, unsafe_hash, frozen)  # type: ignore\n\n    fields: Dict[str, Any] = {\n        field.name: (field.type, field.default if field.default != dataclasses.MISSING else Required)\n        for field in dataclasses.fields(cls)\n    }\n\n    validators = gather_validators(cls)\n    cls.__pydantic_model__ = create_model(\n        cls.__name__, __config__=config, __module__=_cls.__module__, __validators__=validators, **fields\n    )\n\n    cls.__initialised__ = False\n    cls.__validate__ = classmethod(_validate_dataclass)\n    cls.__get_validators__ = classmethod(_get_validators)\n    if post_init_original:\n        cls.__post_init_original__ = post_init_original\n\n    if cls.__pydantic_model__.__config__.validate_assignment and not frozen:\n        cls.__setattr__ = setattr_validate_assignment\n\n    return cls\n\n\nif TYPE_CHECKING:  # pragma: no cover\n    # see https://github.com/python/mypy/issues/6239 for explanation of why we do this\n    from dataclasses import dataclass\nelse:\n\n    def dataclass(\n        _cls: Optional[AnyType] = None,\n        *,\n        init: bool = True,\n        repr: bool = True,\n        eq: bool = True,\n        order: bool = False,\n        unsafe_hash: bool = False,\n        frozen: bool = False,\n        config: Type['BaseConfig'] = None,\n    ) -> Union[Callable[[AnyType], 'DataclassType'], 'DataclassType']:\n        \"\"\"\n        Like the python standard lib dataclasses but with type validation.\n\n        Arguments are the same as for standard dataclasses, except for validate_assignment which has the same meaning\n        as Config.validate_assignment.\n        \"\"\"\n\n        def wrap(cls: AnyType) -> 'DataclassType':\n            return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, config)\n\n        if _cls is None:\n            return wrap\n\n        return wrap(_cls)\n", "path": "pydantic/dataclasses.py"}]}