fV9 4dZddlmZddlZddlZddlZddlmZm Z m Z m Z m Z m Z mZddlmZddlmZmZmZddlmZmZmZdd lmZdd lmZdd lmZdd lm Z dd l!m"Z"m#Z#m$Z$erddl%m&Z&dZ'e dZ(ejRdk\reejTe"e$feddddddddddd d$dZ+eejTe"e$feddddddddddd d%dZ+n|eejTe"e$feddddddddd d&dZ+eejTe"e$feddddddddd d'dZ+eejTe"e$f d(ddddddddddd d)dZ+ee,Z-dejRcxkrdkrnnd*dZ.e.ej^_0ddd dd! d+d"Z1d,d#Z2y)-z7Provide an enhanced dataclass that performs validation.) annotationsN) TYPE_CHECKINGAnyCallableGenericNoReturnTypeVaroverload)warn)Literal TypeGuarddataclass_transform)_config _decorators _typing_extra) _dataclasses)getattr_migration) ConfigDict)PydanticUserError)Field FieldInfo PrivateAttr)PydanticDataclass) dataclassrebuild_dataclass_T )field_specifiersFT. initrepreqorder unsafe_hashfrozenconfigvalidate_on_initkw_onlyslotsc yNr"s ]/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/pydantic/dataclasses.pyrrs c yr.r/) _clsr#r$r%r&r'r(r)r*r+r,s r0rr.s#&r1r#r$r%r&r'r(r)r*cyr.r/r4s r0rrAs r1cyr.r/) r3r#r$r%r&r'r(r)r*s r0rrPs#&r1c  |dusJd|dusJdtjdk\r| | d ni dd d  fd } || S| |S) aUsage docs: https://docs.pydantic.dev/2.9/concepts/dataclasses/ A decorator used to create a Pydantic-enhanced dataclass, similar to the standard Python `dataclass`, but with added validation. This function should be used similarly to `dataclasses.dataclass`. Args: _cls: The target `dataclass`. init: Included for signature compatibility with `dataclasses.dataclass`, and is passed through to `dataclasses.dataclass` when appropriate. If specified, must be set to `False`, as pydantic inserts its own `__init__` function. repr: A boolean indicating whether to include the field in the `__repr__` output. eq: Determines if a `__eq__` method should be generated for the class. order: Determines if comparison magic methods should be generated, such as `__lt__`, but not `__eq__`. unsafe_hash: Determines if a `__hash__` method should be included in the class, as in `dataclasses.dataclass`. frozen: Determines if the generated class should be a 'frozen' `dataclass`, which does not allow its attributes to be modified after it has been initialized. If not set, the value from the provided `config` argument will be used (and will default to `False` otherwise). config: The Pydantic config to use for the `dataclass`. validate_on_init: A deprecated parameter included for backwards compatibility; in V2, all Pydantic dataclasses are validated on init. kw_only: Determines if `__init__` method parameters must be specified by keyword only. Defaults to `False`. slots: Determines if the generated class should be a 'slots' `dataclass`, which does not allow the addition of new attributes after instantiation. Returns: A decorator that accepts a class as its argument and returns a Pydantic `dataclass`. Raises: AssertionError: Raised if `init` is not `False` or `validate_on_init` is `False`. Fz7pydantic.dataclasses.dataclass only supports init=Falsez-validate_on_init=False is no longer supportedr)r+r,c |jD]}t|dg}|D]}t||d}t|ts!d|i}tj dk\r|j rd|d<|jdur|j|d<t||tjdi||jjdi|_ |||j|<y) aMake sure that stdlib `dataclasses` understands `Field` kwargs like `kw_only` To do that, we simply change `x: int = pydantic.Field(..., kw_only=True)` into `x: int = dataclasses.field(default=pydantic.Field(..., kw_only=True), kw_only=True)` __annotations__NdefaultrTr+r$r/)__mro__getattr isinstancersys version_infor+r$setattr dataclassesfield__dict__getr9)clsannotation_clsr field_name field_value field_argss r0make_pydantic_fields_compatiblez2dataclass..make_pydantic_fields_compatibles"kkN".2CRHK) %c:t< !+y9%.{#; ##w.;3F3F,0Jy)##4/)4)9)9Jv&Z):):)HZ)HI<<##$56>*,C'2=j2I##J/-* *r1c 2ddlm}||rtd|jdd|}  n t |dd}t j |}tjj|}|j}tj|rNd}|f}t|trt|j}||fz}t!j"|j|}| / } |j$r1t'd |jd t(d n|j$xsd } t+j,|fd | d }||_||_ |j0|_|j2|_d |_tj6||d d|S)zCreate a Pydantic dataclass from a regular dataclass. Args: cls: The class to create the Pydantic dataclass from. Returns: A Pydantic dataclass. r)is_model_classz(Cannot create a Pydantic dataclass from z" as it is already a Pydantic modelzdataclass-on-model)codeN__pydantic_config__zN`frozen` is set via both the `dataclass` decorator and `config` for dataclass zW.This is not recommended. The `frozen` specification on `dataclass` will take priority.)category stacklevelFT)r#r$r%r&r'r( raise_errorstypes_namespace)_internal._utilsrLr__name__r<r ConfigWrapperrDecoratorInfosbuild__doc___pydantic_dataclassesis_builtin_dataclass issubclassr__parameters__types new_classr(r UserWarningrAr__pydantic_decorators__ __module__ __qualname____pydantic_complete__complete_dataclass)rErL original_cls config_dictconfig_wrapper decorators original_docbases generic_basefrozen_r)r%r(kwargsrJr&r$r's r0create_dataclassz#dataclass..create_dataclasss 5 # #:3<<.Hjk)   !' 2fEZ\`8a  ..{; //55c: {{ 5 5c : L FE#w'&s'9'9: ///#,,6C',  G$$deheqeqdtumm( %++4uG##   #    '1#" %00'44$)!00nSXjno r1)rE type[Any]returnNone)rErqrrtype[PydanticDataclass])r>r?)r3r#r$r%r&r'r(r)r*r+r,rprorJs `````` @@r0rr`su\ 5=SSS= 5 (Y*YY ( 7"$u5!JFMM^ $| G1A$1GGr1)r)r ctd)a9This function does nothing but raise an error that is as similar as possible to what you'd get if you were to try calling `InitVar[int]()` without this monkeypatch. The whole purpose is just to ensure typing._type_check does not error if the type hint evaluates to `InitVar[]`. z 'InitVar' object is not callable) TypeError)argsros r0 _call_initvarrzs :;;r1rO)forcerS_parent_namespace_depth_types_namespacec*|s |jry||j}n:|dkDrtj|xsi}|}ni}tj||}t j |tj|jd||S)axTry to rebuild the pydantic-core schema for the dataclass. This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails. This is analogous to `BaseModel.model_rebuild`. Args: cls: The class to rebuild the pydantic-core schema for. force: Whether to force the rebuilding of the schema, defaults to `False`. raise_errors: Whether to raise errors, defaults to `True`. _parent_namespace_depth: The depth level of the parent namespace, defaults to 2. _types_namespace: The types namespace, defaults to `None`. Returns: Returns `None` if the schema is already "complete" and rebuilding was not required. If rebuilding _was_ required, returns `True` if rebuilding was successful, otherwise `False`. Nr) parent_depthF)checkrR) recopyrparent_frame_namespacemerge_cls_and_parent_nsr[rfrrWrN)rEr{rSr|r}rTframe_parent_nss r0rrs4 S..  '5E5J5J5LO&*"/"F"FTk"l"rpr#2"$+CCCYO$77   ! !#"9"9 G%+   r1cl d|jvxrtj|S#t$rYywxYw)zWhether a class is a pydantic dataclass. Args: class_: The class. Returns: `True` if the class is a pydantic dataclass, `False` otherwise. __pydantic_validator__F)rCrA is_dataclassAttributeError)class_s r0is_pydantic_dataclassrLs9'6??:_{?W?WX^?__ s $' 33)r#Literal[False]r$boolr%rr&rr'rr(rr) ConfigDict | type[object] | Noner* bool | Noner+rr,rrr-Callable[[type[_T]], type[PydanticDataclass]])r3type[_T]r#rr$rr%rr&rr'rr(rr)rr*rr+rr,rrrrt)r#rr$rr%rr&rr'rr(rr)rr*rrrr)r3rr#rr$rr%rr&rr'rr(rr)rr*rrrrtr.)r3ztype[_T] | Noner#rr$rr%rr&rr'rr(rr)rr*rr+rr,rrrzGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass])ryrrorrrr) rErtr{rrSrr|intr}zdict[str, Any] | Nonerrr)rrqrrz"TypeGuard[type[PydanticDataclass]])3rZ __future__r _annotationsrAr>r_typingrrrrrr r warningsr typing_extensionsr r r _internalrrrrr[ _migrationrr)rerrorsrfieldsrrr_internal._dataclassesr__all__rr?rBrrV __getattr__rzInitVar__call__rrr/r1r0rs=2 UUUEE::<)%119 * T]w;+<+