We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Feature request] [VS Code] No auto complete when using pydantic.dataclasses.dataclass
# Feature request

Similar to the issue that #2721 solves, VS Code can't auto complete models constructor parameters when using `pydantic.dataclasses.dataclass`.

Output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`:
```
             pydantic version: 1.9.0
            pydantic compiled: True
                 install path: /tmp/hello-world/.venv/lib/python3.10/site-packages/pydantic
               python version: 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]
                     platform: Linux-5.10.105-1-MANJARO-x86_64-with-glibc2.35
     optional deps. installed: ['typing-extensions']
```

Example Code:
```python
import pydantic
from pydantic.dataclasses import dataclass

@dataclass
class Hello:
    n: int
    s: str

hello = Hello(n=1, s="a")
hello.n
```

VS Code:

https://user-images.githubusercontent.com/13181797/164987610-f6704c45-3afd-4b92-9a8a-b9addeb83dd9.mp4



# Workaround:
You can import python pure dataclass instead of pydantic's dataclass when type checking, as stated by @JosXa [here](https://github.com/microsoft/python-language-server/issues/1898#issuecomment-743645817):

```python
from pydantic.dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from dataclasses import dataclass
else:
    from pydantic.dataclasses import dataclass as dataclass
```

--- 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 from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, overload
2 
3 from .class_validators import gather_all_validators
4 from .error_wrappers import ValidationError
5 from .errors import DataclassTypeError
6 from .fields import Field, FieldInfo, Required, Undefined
7 from .main import create_model, validate_model
8 from .typing import resolve_annotations
9 from .utils import ClassAttribute
10 
11 if TYPE_CHECKING:
12     from .config import BaseConfig
13     from .main import BaseModel
14     from .typing import CallableGenerator, NoArgAnyCallable
15 
16     DataclassT = TypeVar('DataclassT', bound='Dataclass')
17 
18     class Dataclass:
19         __pydantic_model__: Type[BaseModel]
20         __initialised__: bool
21         __post_init_original__: Optional[Callable[..., None]]
22         __processed__: Optional[ClassAttribute]
23         __has_field_info_default__: bool  # whether or not a `pydantic.Field` is used as default value
24 
25         def __init__(self, *args: Any, **kwargs: Any) -> None:
26             pass
27 
28         @classmethod
29         def __get_validators__(cls: Type['Dataclass']) -> 'CallableGenerator':
30             pass
31 
32         @classmethod
33         def __validate__(cls: Type['DataclassT'], v: Any) -> 'DataclassT':
34             pass
35 
36         def __call__(self: 'DataclassT', *args: Any, **kwargs: Any) -> 'DataclassT':
37             pass
38 
39 
40 def _validate_dataclass(cls: Type['DataclassT'], v: Any) -> 'DataclassT':
41     if isinstance(v, cls):
42         return v
43     elif isinstance(v, (list, tuple)):
44         return cls(*v)
45     elif isinstance(v, dict):
46         return cls(**v)
47     # In nested dataclasses, v can be of type `dataclasses.dataclass`.
48     # But to validate fields `cls` will be in fact a `pydantic.dataclasses.dataclass`,
49     # which inherits directly from the class of `v`.
50     elif is_builtin_dataclass(v) and cls.__bases__[0] is type(v):
51         import dataclasses
52 
53         return cls(**dataclasses.asdict(v))
54     else:
55         raise DataclassTypeError(class_name=cls.__name__)
56 
57 
58 def _get_validators(cls: Type['Dataclass']) -> 'CallableGenerator':
59     yield cls.__validate__
60 
61 
62 def setattr_validate_assignment(self: 'Dataclass', name: str, value: Any) -> None:
63     if self.__initialised__:
64         d = dict(self.__dict__)
65         d.pop(name, None)
66         known_field = self.__pydantic_model__.__fields__.get(name, None)
67         if known_field:
68             value, error_ = known_field.validate(value, d, loc=name, cls=self.__class__)
69             if error_:
70                 raise ValidationError([error_], self.__class__)
71 
72     object.__setattr__(self, name, value)
73 
74 
75 def is_builtin_dataclass(_cls: Type[Any]) -> bool:
76     """
77     `dataclasses.is_dataclass` is True if one of the class parents is a `dataclass`.
78     This is why we also add a class attribute `__processed__` to only consider 'direct' built-in dataclasses
79     """
80     import dataclasses
81 
82     return not hasattr(_cls, '__processed__') and dataclasses.is_dataclass(_cls)
83 
84 
85 def _generate_pydantic_post_init(
86     post_init_original: Optional[Callable[..., None]], post_init_post_parse: Optional[Callable[..., None]]
87 ) -> Callable[..., None]:
88     def _pydantic_post_init(self: 'Dataclass', *initvars: Any) -> None:
89         if post_init_original is not None:
90             post_init_original(self, *initvars)
91 
92         if getattr(self, '__has_field_info_default__', False):
93             # We need to remove `FieldInfo` values since they are not valid as input
94             # It's ok to do that because they are obviously the default values!
95             input_data = {k: v for k, v in self.__dict__.items() if not isinstance(v, FieldInfo)}
96         else:
97             input_data = self.__dict__
98         d, _, validation_error = validate_model(self.__pydantic_model__, input_data, cls=self.__class__)
99         if validation_error:
100             raise validation_error
101         object.__setattr__(self, '__dict__', {**getattr(self, '__dict__', {}), **d})
102         object.__setattr__(self, '__initialised__', True)
103         if post_init_post_parse is not None:
104             post_init_post_parse(self, *initvars)
105 
106     return _pydantic_post_init
107 
108 
109 def _process_class(
110     _cls: Type[Any],
111     init: bool,
112     repr: bool,
113     eq: bool,
114     order: bool,
115     unsafe_hash: bool,
116     frozen: bool,
117     config: Optional[Type[Any]],
118 ) -> Type['Dataclass']:
119     import dataclasses
120 
121     post_init_original = getattr(_cls, '__post_init__', None)
122     if post_init_original and post_init_original.__name__ == '_pydantic_post_init':
123         post_init_original = None
124     if not post_init_original:
125         post_init_original = getattr(_cls, '__post_init_original__', None)
126 
127     post_init_post_parse = getattr(_cls, '__post_init_post_parse__', None)
128 
129     _pydantic_post_init = _generate_pydantic_post_init(post_init_original, post_init_post_parse)
130 
131     # If the class is already a dataclass, __post_init__ will not be called automatically
132     # so no validation will be added.
133     # We hence create dynamically a new dataclass:
134     # ```
135     # @dataclasses.dataclass
136     # class NewClass(_cls):
137     #   __post_init__ = _pydantic_post_init
138     # ```
139     # with the exact same fields as the base dataclass
140     # and register it on module level to address pickle problem:
141     # https://github.com/samuelcolvin/pydantic/issues/2111
142     if is_builtin_dataclass(_cls):
143         uniq_class_name = f'_Pydantic_{_cls.__name__}_{id(_cls)}'
144         _cls = type(
145             # for pretty output new class will have the name as original
146             _cls.__name__,
147             (_cls,),
148             {
149                 '__annotations__': resolve_annotations(_cls.__annotations__, _cls.__module__),
150                 '__post_init__': _pydantic_post_init,
151                 # attrs for pickle to find this class
152                 '__module__': __name__,
153                 '__qualname__': uniq_class_name,
154             },
155         )
156         globals()[uniq_class_name] = _cls
157     else:
158         _cls.__post_init__ = _pydantic_post_init
159     cls: Type['Dataclass'] = dataclasses.dataclass(  # type: ignore
160         _cls, init=init, repr=repr, eq=eq, order=order, unsafe_hash=unsafe_hash, frozen=frozen
161     )
162     cls.__processed__ = ClassAttribute('__processed__', True)
163 
164     field_definitions: Dict[str, Any] = {}
165     for field in dataclasses.fields(cls):
166         default: Any = Undefined
167         default_factory: Optional['NoArgAnyCallable'] = None
168         field_info: FieldInfo
169 
170         if field.default is not dataclasses.MISSING:
171             default = field.default
172         elif field.default_factory is not dataclasses.MISSING:
173             default_factory = field.default_factory
174         else:
175             default = Required
176 
177         if isinstance(default, FieldInfo):
178             field_info = default
179             cls.__has_field_info_default__ = True
180         else:
181             field_info = Field(default=default, default_factory=default_factory, **field.metadata)
182 
183         field_definitions[field.name] = (field.type, field_info)
184 
185     validators = gather_all_validators(cls)
186     cls.__pydantic_model__ = create_model(
187         cls.__name__,
188         __config__=config,
189         __module__=_cls.__module__,
190         __validators__=validators,
191         __cls_kwargs__={'__resolve_forward_refs__': False},
192         **field_definitions,
193     )
194 
195     cls.__initialised__ = False
196     cls.__validate__ = classmethod(_validate_dataclass)  # type: ignore[assignment]
197     cls.__get_validators__ = classmethod(_get_validators)  # type: ignore[assignment]
198     if post_init_original:
199         cls.__post_init_original__ = post_init_original
200 
201     if cls.__pydantic_model__.__config__.validate_assignment and not frozen:
202         cls.__setattr__ = setattr_validate_assignment  # type: ignore[assignment]
203 
204     cls.__pydantic_model__.__try_update_forward_refs__(**{cls.__name__: cls})
205 
206     return cls
207 
208 
209 @overload
210 def dataclass(
211     *,
212     init: bool = True,
213     repr: bool = True,
214     eq: bool = True,
215     order: bool = False,
216     unsafe_hash: bool = False,
217     frozen: bool = False,
218     config: Type[Any] = None,
219 ) -> Callable[[Type[Any]], Type['Dataclass']]:
220     ...
221 
222 
223 @overload
224 def dataclass(
225     _cls: Type[Any],
226     *,
227     init: bool = True,
228     repr: bool = True,
229     eq: bool = True,
230     order: bool = False,
231     unsafe_hash: bool = False,
232     frozen: bool = False,
233     config: Type[Any] = None,
234 ) -> Type['Dataclass']:
235     ...
236 
237 
238 def dataclass(
239     _cls: Optional[Type[Any]] = None,
240     *,
241     init: bool = True,
242     repr: bool = True,
243     eq: bool = True,
244     order: bool = False,
245     unsafe_hash: bool = False,
246     frozen: bool = False,
247     config: Type[Any] = None,
248 ) -> Union[Callable[[Type[Any]], Type['Dataclass']], Type['Dataclass']]:
249     """
250     Like the python standard lib dataclasses but with type validation.
251 
252     Arguments are the same as for standard dataclasses, except for validate_assignment which has the same meaning
253     as Config.validate_assignment.
254     """
255 
256     def wrap(cls: Type[Any]) -> Type['Dataclass']:
257         return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen, config)
258 
259     if _cls is None:
260         return wrap
261 
262     return wrap(_cls)
263 
264 
265 def make_dataclass_validator(_cls: Type[Any], config: Type['BaseConfig']) -> 'CallableGenerator':
266     """
267     Create a pydantic.dataclass from a builtin dataclass to add type validation
268     and yield the validators
269     It retrieves the parameters of the dataclass and forwards them to the newly created dataclass
270     """
271     dataclass_params = _cls.__dataclass_params__
272     stdlib_dataclass_parameters = {param: getattr(dataclass_params, param) for param in dataclass_params.__slots__}
273     cls = dataclass(_cls, config=config, **stdlib_dataclass_parameters)
274     yield from _get_validators(cls)
275
```
--- 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()

```

diff --git a/pydantic/dataclasses.py b/pydantic/dataclasses.py
--- a/pydantic/dataclasses.py
+++ b/pydantic/dataclasses.py
@@ -1,10 +1,10 @@
-from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, overload
+from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Optional, Type, TypeVar, Union, overload
 
 from .class_validators import gather_all_validators
 from .error_wrappers import ValidationError
 from .errors import DataclassTypeError
 from .fields import Field, FieldInfo, Required, Undefined
-from .main import create_model, validate_model
+from .main import __dataclass_transform__, create_model, validate_model
 from .typing import resolve_annotations
 from .utils import ClassAttribute
 
@@ -16,11 +16,11 @@
     DataclassT = TypeVar('DataclassT', bound='Dataclass')
 
     class Dataclass:
-        __pydantic_model__: Type[BaseModel]
-        __initialised__: bool
-        __post_init_original__: Optional[Callable[..., None]]
-        __processed__: Optional[ClassAttribute]
-        __has_field_info_default__: bool  # whether or not a `pydantic.Field` is used as default value
+        __pydantic_model__: ClassVar[Type[BaseModel]]
+        __initialised__: ClassVar[bool]
+        __post_init_original__: ClassVar[Optional[Callable[..., None]]]
+        __processed__: ClassVar[Optional[ClassAttribute]]
+        __has_field_info_default__: ClassVar[bool]  # whether or not a `pydantic.Field` is used as default value
 
         def __init__(self, *args: Any, **kwargs: Any) -> None:
             pass
@@ -206,6 +206,7 @@
     return cls
 
 
+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
 @overload
 def dataclass(
     *,
@@ -220,6 +221,7 @@
     ...
 
 
+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
 @overload
 def dataclass(
     _cls: Type[Any],
@@ -235,6 +237,7 @@
     ...
 
 
+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))
 def dataclass(
     _cls: Optional[Type[Any]] = None,
     *,

{"golden_diff": "diff --git a/pydantic/dataclasses.py b/pydantic/dataclasses.py\n--- a/pydantic/dataclasses.py\n+++ b/pydantic/dataclasses.py\n@@ -1,10 +1,10 @@\n-from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, overload\n+from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Optional, Type, TypeVar, Union, overload\n \n from .class_validators import gather_all_validators\n from .error_wrappers import ValidationError\n from .errors import DataclassTypeError\n from .fields import Field, FieldInfo, Required, Undefined\n-from .main import create_model, validate_model\n+from .main import __dataclass_transform__, create_model, validate_model\n from .typing import resolve_annotations\n from .utils import ClassAttribute\n \n@@ -16,11 +16,11 @@\n     DataclassT = TypeVar('DataclassT', bound='Dataclass')\n \n     class Dataclass:\n-        __pydantic_model__: Type[BaseModel]\n-        __initialised__: bool\n-        __post_init_original__: Optional[Callable[..., None]]\n-        __processed__: Optional[ClassAttribute]\n-        __has_field_info_default__: bool  # whether or not a `pydantic.Field` is used as default value\n+        __pydantic_model__: ClassVar[Type[BaseModel]]\n+        __initialised__: ClassVar[bool]\n+        __post_init_original__: ClassVar[Optional[Callable[..., None]]]\n+        __processed__: ClassVar[Optional[ClassAttribute]]\n+        __has_field_info_default__: ClassVar[bool]  # whether or not a `pydantic.Field` is used as default value\n \n         def __init__(self, *args: Any, **kwargs: Any) -> None:\n             pass\n@@ -206,6 +206,7 @@\n     return cls\n \n \n+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\n @overload\n def dataclass(\n     *,\n@@ -220,6 +221,7 @@\n     ...\n \n \n+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\n @overload\n def dataclass(\n     _cls: Type[Any],\n@@ -235,6 +237,7 @@\n     ...\n \n \n+@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\n def dataclass(\n     _cls: Optional[Type[Any]] = None,\n     *,\n", "issue": "[Feature request] [VS Code] No auto complete when using pydantic.dataclasses.dataclass\n# Feature request\r\n\r\nSimilar to the issue that #2721 solves, VS Code can't auto complete models constructor parameters when using `pydantic.dataclasses.dataclass`.\r\n\r\nOutput of `python -c \"import pydantic.utils; print(pydantic.utils.version_info())\"`:\r\n```\r\n             pydantic version: 1.9.0\r\n            pydantic compiled: True\r\n                 install path: /tmp/hello-world/.venv/lib/python3.10/site-packages/pydantic\r\n               python version: 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0]\r\n                     platform: Linux-5.10.105-1-MANJARO-x86_64-with-glibc2.35\r\n     optional deps. installed: ['typing-extensions']\r\n```\r\n\r\nExample Code:\r\n```python\r\nimport pydantic\r\nfrom pydantic.dataclasses import dataclass\r\n\r\n@dataclass\r\nclass Hello:\r\n    n: int\r\n    s: str\r\n\r\nhello = Hello(n=1, s=\"a\")\r\nhello.n\r\n```\r\n\r\nVS Code:\r\n\r\nhttps://user-images.githubusercontent.com/13181797/164987610-f6704c45-3afd-4b92-9a8a-b9addeb83dd9.mp4\r\n\r\n\r\n\r\n# Workaround:\r\nYou can import python pure dataclass instead of pydantic's dataclass when type checking, as stated by @JosXa [here](https://github.com/microsoft/python-language-server/issues/1898#issuecomment-743645817):\r\n\r\n```python\r\nfrom pydantic.dataclasses import dataclass\r\nfrom typing import TYPE_CHECKING\r\nif TYPE_CHECKING:\r\n    from dataclasses import dataclass\r\nelse:\r\n    from pydantic.dataclasses import dataclass as dataclass\r\n```\n", "before_files": [{"content": "from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, overload\n\nfrom .class_validators import gather_all_validators\nfrom .error_wrappers import ValidationError\nfrom .errors import DataclassTypeError\nfrom .fields import Field, FieldInfo, Required, Undefined\nfrom .main import create_model, validate_model\nfrom .typing import resolve_annotations\nfrom .utils import ClassAttribute\n\nif TYPE_CHECKING:\n    from .config import BaseConfig\n    from .main import BaseModel\n    from .typing import CallableGenerator, NoArgAnyCallable\n\n    DataclassT = TypeVar('DataclassT', bound='Dataclass')\n\n    class Dataclass:\n        __pydantic_model__: Type[BaseModel]\n        __initialised__: bool\n        __post_init_original__: Optional[Callable[..., None]]\n        __processed__: Optional[ClassAttribute]\n        __has_field_info_default__: bool  # whether or not a `pydantic.Field` is used as default value\n\n        def __init__(self, *args: Any, **kwargs: Any) -> None:\n            pass\n\n        @classmethod\n        def __get_validators__(cls: Type['Dataclass']) -> 'CallableGenerator':\n            pass\n\n        @classmethod\n        def __validate__(cls: Type['DataclassT'], v: Any) -> 'DataclassT':\n            pass\n\n        def __call__(self: 'DataclassT', *args: Any, **kwargs: Any) -> 'DataclassT':\n            pass\n\n\ndef _validate_dataclass(cls: Type['DataclassT'], v: Any) -> 'DataclassT':\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    # In nested dataclasses, v can be of type `dataclasses.dataclass`.\n    # But to validate fields `cls` will be in fact a `pydantic.dataclasses.dataclass`,\n    # which inherits directly from the class of `v`.\n    elif is_builtin_dataclass(v) and cls.__bases__[0] is type(v):\n        import dataclasses\n\n        return cls(**dataclasses.asdict(v))\n    else:\n        raise DataclassTypeError(class_name=cls.__name__)\n\n\ndef _get_validators(cls: Type['Dataclass']) -> 'CallableGenerator':\n    yield cls.__validate__\n\n\ndef setattr_validate_assignment(self: 'Dataclass', 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_], self.__class__)\n\n    object.__setattr__(self, name, value)\n\n\ndef is_builtin_dataclass(_cls: Type[Any]) -> bool:\n    \"\"\"\n    `dataclasses.is_dataclass` is True if one of the class parents is a `dataclass`.\n    This is why we also add a class attribute `__processed__` to only consider 'direct' built-in dataclasses\n    \"\"\"\n    import dataclasses\n\n    return not hasattr(_cls, '__processed__') and dataclasses.is_dataclass(_cls)\n\n\ndef _generate_pydantic_post_init(\n    post_init_original: Optional[Callable[..., None]], post_init_post_parse: Optional[Callable[..., None]]\n) -> Callable[..., None]:\n    def _pydantic_post_init(self: 'Dataclass', *initvars: Any) -> None:\n        if post_init_original is not None:\n            post_init_original(self, *initvars)\n\n        if getattr(self, '__has_field_info_default__', False):\n            # We need to remove `FieldInfo` values since they are not valid as input\n            # It's ok to do that because they are obviously the default values!\n            input_data = {k: v for k, v in self.__dict__.items() if not isinstance(v, FieldInfo)}\n        else:\n            input_data = self.__dict__\n        d, _, validation_error = validate_model(self.__pydantic_model__, input_data, cls=self.__class__)\n        if validation_error:\n            raise validation_error\n        object.__setattr__(self, '__dict__', {**getattr(self, '__dict__', {}), **d})\n        object.__setattr__(self, '__initialised__', True)\n        if post_init_post_parse is not None:\n            post_init_post_parse(self, *initvars)\n\n    return _pydantic_post_init\n\n\ndef _process_class(\n    _cls: Type[Any],\n    init: bool,\n    repr: bool,\n    eq: bool,\n    order: bool,\n    unsafe_hash: bool,\n    frozen: bool,\n    config: Optional[Type[Any]],\n) -> Type['Dataclass']:\n    import dataclasses\n\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    _pydantic_post_init = _generate_pydantic_post_init(post_init_original, post_init_post_parse)\n\n    # If the class is already a dataclass, __post_init__ will not be called automatically\n    # so no validation will be added.\n    # We hence create dynamically a new dataclass:\n    # ```\n    # @dataclasses.dataclass\n    # class NewClass(_cls):\n    #   __post_init__ = _pydantic_post_init\n    # ```\n    # with the exact same fields as the base dataclass\n    # and register it on module level to address pickle problem:\n    # https://github.com/samuelcolvin/pydantic/issues/2111\n    if is_builtin_dataclass(_cls):\n        uniq_class_name = f'_Pydantic_{_cls.__name__}_{id(_cls)}'\n        _cls = type(\n            # for pretty output new class will have the name as original\n            _cls.__name__,\n            (_cls,),\n            {\n                '__annotations__': resolve_annotations(_cls.__annotations__, _cls.__module__),\n                '__post_init__': _pydantic_post_init,\n                # attrs for pickle to find this class\n                '__module__': __name__,\n                '__qualname__': uniq_class_name,\n            },\n        )\n        globals()[uniq_class_name] = _cls\n    else:\n        _cls.__post_init__ = _pydantic_post_init\n    cls: Type['Dataclass'] = dataclasses.dataclass(  # type: ignore\n        _cls, init=init, repr=repr, eq=eq, order=order, unsafe_hash=unsafe_hash, frozen=frozen\n    )\n    cls.__processed__ = ClassAttribute('__processed__', True)\n\n    field_definitions: Dict[str, Any] = {}\n    for field in dataclasses.fields(cls):\n        default: Any = Undefined\n        default_factory: Optional['NoArgAnyCallable'] = None\n        field_info: FieldInfo\n\n        if field.default is not dataclasses.MISSING:\n            default = field.default\n        elif field.default_factory is not dataclasses.MISSING:\n            default_factory = field.default_factory\n        else:\n            default = Required\n\n        if isinstance(default, FieldInfo):\n            field_info = default\n            cls.__has_field_info_default__ = True\n        else:\n            field_info = Field(default=default, default_factory=default_factory, **field.metadata)\n\n        field_definitions[field.name] = (field.type, field_info)\n\n    validators = gather_all_validators(cls)\n    cls.__pydantic_model__ = create_model(\n        cls.__name__,\n        __config__=config,\n        __module__=_cls.__module__,\n        __validators__=validators,\n        __cls_kwargs__={'__resolve_forward_refs__': False},\n        **field_definitions,\n    )\n\n    cls.__initialised__ = False\n    cls.__validate__ = classmethod(_validate_dataclass)  # type: ignore[assignment]\n    cls.__get_validators__ = classmethod(_get_validators)  # type: ignore[assignment]\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  # type: ignore[assignment]\n\n    cls.__pydantic_model__.__try_update_forward_refs__(**{cls.__name__: cls})\n\n    return cls\n\n\n@overload\ndef dataclass(\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[Any] = None,\n) -> Callable[[Type[Any]], Type['Dataclass']]:\n    ...\n\n\n@overload\ndef dataclass(\n    _cls: Type[Any],\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[Any] = None,\n) -> Type['Dataclass']:\n    ...\n\n\ndef dataclass(\n    _cls: Optional[Type[Any]] = 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[Any] = None,\n) -> Union[Callable[[Type[Any]], Type['Dataclass']], Type['Dataclass']]:\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: Type[Any]) -> Type['Dataclass']:\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\n\ndef make_dataclass_validator(_cls: Type[Any], config: Type['BaseConfig']) -> 'CallableGenerator':\n    \"\"\"\n    Create a pydantic.dataclass from a builtin dataclass to add type validation\n    and yield the validators\n    It retrieves the parameters of the dataclass and forwards them to the newly created dataclass\n    \"\"\"\n    dataclass_params = _cls.__dataclass_params__\n    stdlib_dataclass_parameters = {param: getattr(dataclass_params, param) for param in dataclass_params.__slots__}\n    cls = dataclass(_cls, config=config, **stdlib_dataclass_parameters)\n    yield from _get_validators(cls)\n", "path": "pydantic/dataclasses.py"}], "after_files": [{"content": "from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Optional, Type, TypeVar, Union, overload\n\nfrom .class_validators import gather_all_validators\nfrom .error_wrappers import ValidationError\nfrom .errors import DataclassTypeError\nfrom .fields import Field, FieldInfo, Required, Undefined\nfrom .main import __dataclass_transform__, create_model, validate_model\nfrom .typing import resolve_annotations\nfrom .utils import ClassAttribute\n\nif TYPE_CHECKING:\n    from .config import BaseConfig\n    from .main import BaseModel\n    from .typing import CallableGenerator, NoArgAnyCallable\n\n    DataclassT = TypeVar('DataclassT', bound='Dataclass')\n\n    class Dataclass:\n        __pydantic_model__: ClassVar[Type[BaseModel]]\n        __initialised__: ClassVar[bool]\n        __post_init_original__: ClassVar[Optional[Callable[..., None]]]\n        __processed__: ClassVar[Optional[ClassAttribute]]\n        __has_field_info_default__: ClassVar[bool]  # whether or not a `pydantic.Field` is used as default value\n\n        def __init__(self, *args: Any, **kwargs: Any) -> None:\n            pass\n\n        @classmethod\n        def __get_validators__(cls: Type['Dataclass']) -> 'CallableGenerator':\n            pass\n\n        @classmethod\n        def __validate__(cls: Type['DataclassT'], v: Any) -> 'DataclassT':\n            pass\n\n        def __call__(self: 'DataclassT', *args: Any, **kwargs: Any) -> 'DataclassT':\n            pass\n\n\ndef _validate_dataclass(cls: Type['DataclassT'], v: Any) -> 'DataclassT':\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    # In nested dataclasses, v can be of type `dataclasses.dataclass`.\n    # But to validate fields `cls` will be in fact a `pydantic.dataclasses.dataclass`,\n    # which inherits directly from the class of `v`.\n    elif is_builtin_dataclass(v) and cls.__bases__[0] is type(v):\n        import dataclasses\n\n        return cls(**dataclasses.asdict(v))\n    else:\n        raise DataclassTypeError(class_name=cls.__name__)\n\n\ndef _get_validators(cls: Type['Dataclass']) -> 'CallableGenerator':\n    yield cls.__validate__\n\n\ndef setattr_validate_assignment(self: 'Dataclass', 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_], self.__class__)\n\n    object.__setattr__(self, name, value)\n\n\ndef is_builtin_dataclass(_cls: Type[Any]) -> bool:\n    \"\"\"\n    `dataclasses.is_dataclass` is True if one of the class parents is a `dataclass`.\n    This is why we also add a class attribute `__processed__` to only consider 'direct' built-in dataclasses\n    \"\"\"\n    import dataclasses\n\n    return not hasattr(_cls, '__processed__') and dataclasses.is_dataclass(_cls)\n\n\ndef _generate_pydantic_post_init(\n    post_init_original: Optional[Callable[..., None]], post_init_post_parse: Optional[Callable[..., None]]\n) -> Callable[..., None]:\n    def _pydantic_post_init(self: 'Dataclass', *initvars: Any) -> None:\n        if post_init_original is not None:\n            post_init_original(self, *initvars)\n\n        if getattr(self, '__has_field_info_default__', False):\n            # We need to remove `FieldInfo` values since they are not valid as input\n            # It's ok to do that because they are obviously the default values!\n            input_data = {k: v for k, v in self.__dict__.items() if not isinstance(v, FieldInfo)}\n        else:\n            input_data = self.__dict__\n        d, _, validation_error = validate_model(self.__pydantic_model__, input_data, cls=self.__class__)\n        if validation_error:\n            raise validation_error\n        object.__setattr__(self, '__dict__', {**getattr(self, '__dict__', {}), **d})\n        object.__setattr__(self, '__initialised__', True)\n        if post_init_post_parse is not None:\n            post_init_post_parse(self, *initvars)\n\n    return _pydantic_post_init\n\n\ndef _process_class(\n    _cls: Type[Any],\n    init: bool,\n    repr: bool,\n    eq: bool,\n    order: bool,\n    unsafe_hash: bool,\n    frozen: bool,\n    config: Optional[Type[Any]],\n) -> Type['Dataclass']:\n    import dataclasses\n\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    _pydantic_post_init = _generate_pydantic_post_init(post_init_original, post_init_post_parse)\n\n    # If the class is already a dataclass, __post_init__ will not be called automatically\n    # so no validation will be added.\n    # We hence create dynamically a new dataclass:\n    # ```\n    # @dataclasses.dataclass\n    # class NewClass(_cls):\n    #   __post_init__ = _pydantic_post_init\n    # ```\n    # with the exact same fields as the base dataclass\n    # and register it on module level to address pickle problem:\n    # https://github.com/samuelcolvin/pydantic/issues/2111\n    if is_builtin_dataclass(_cls):\n        uniq_class_name = f'_Pydantic_{_cls.__name__}_{id(_cls)}'\n        _cls = type(\n            # for pretty output new class will have the name as original\n            _cls.__name__,\n            (_cls,),\n            {\n                '__annotations__': resolve_annotations(_cls.__annotations__, _cls.__module__),\n                '__post_init__': _pydantic_post_init,\n                # attrs for pickle to find this class\n                '__module__': __name__,\n                '__qualname__': uniq_class_name,\n            },\n        )\n        globals()[uniq_class_name] = _cls\n    else:\n        _cls.__post_init__ = _pydantic_post_init\n    cls: Type['Dataclass'] = dataclasses.dataclass(  # type: ignore\n        _cls, init=init, repr=repr, eq=eq, order=order, unsafe_hash=unsafe_hash, frozen=frozen\n    )\n    cls.__processed__ = ClassAttribute('__processed__', True)\n\n    field_definitions: Dict[str, Any] = {}\n    for field in dataclasses.fields(cls):\n        default: Any = Undefined\n        default_factory: Optional['NoArgAnyCallable'] = None\n        field_info: FieldInfo\n\n        if field.default is not dataclasses.MISSING:\n            default = field.default\n        elif field.default_factory is not dataclasses.MISSING:\n            default_factory = field.default_factory\n        else:\n            default = Required\n\n        if isinstance(default, FieldInfo):\n            field_info = default\n            cls.__has_field_info_default__ = True\n        else:\n            field_info = Field(default=default, default_factory=default_factory, **field.metadata)\n\n        field_definitions[field.name] = (field.type, field_info)\n\n    validators = gather_all_validators(cls)\n    cls.__pydantic_model__ = create_model(\n        cls.__name__,\n        __config__=config,\n        __module__=_cls.__module__,\n        __validators__=validators,\n        __cls_kwargs__={'__resolve_forward_refs__': False},\n        **field_definitions,\n    )\n\n    cls.__initialised__ = False\n    cls.__validate__ = classmethod(_validate_dataclass)  # type: ignore[assignment]\n    cls.__get_validators__ = classmethod(_get_validators)  # type: ignore[assignment]\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  # type: ignore[assignment]\n\n    cls.__pydantic_model__.__try_update_forward_refs__(**{cls.__name__: cls})\n\n    return cls\n\n\n@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\n@overload\ndef dataclass(\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[Any] = None,\n) -> Callable[[Type[Any]], Type['Dataclass']]:\n    ...\n\n\n@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\n@overload\ndef dataclass(\n    _cls: Type[Any],\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[Any] = None,\n) -> Type['Dataclass']:\n    ...\n\n\n@__dataclass_transform__(kw_only_default=True, field_descriptors=(Field, FieldInfo))\ndef dataclass(\n    _cls: Optional[Type[Any]] = 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[Any] = None,\n) -> Union[Callable[[Type[Any]], Type['Dataclass']], Type['Dataclass']]:\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: Type[Any]) -> Type['Dataclass']:\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\n\ndef make_dataclass_validator(_cls: Type[Any], config: Type['BaseConfig']) -> 'CallableGenerator':\n    \"\"\"\n    Create a pydantic.dataclass from a builtin dataclass to add type validation\n    and yield the validators\n    It retrieves the parameters of the dataclass and forwards them to the newly created dataclass\n    \"\"\"\n    dataclass_params = _cls.__dataclass_params__\n    stdlib_dataclass_parameters = {param: getattr(dataclass_params, param) for param in dataclass_params.__slots__}\n    cls = dataclass(_cls, config=config, **stdlib_dataclass_parameters)\n    yield from _get_validators(cls)\n", "path": "pydantic/dataclasses.py"}]}