XjJ FdZddlmZddlZddlZddlZddlZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZddlmZmZmZmZmZdd lmZdd lmZdd l m!Z!dd l"m#Z#dd l$m%Z%m&Z&m'Z'e r ddl(m)Z)ddl*m+Z+dZ,edZ-ej\dk\reej^e%e'feddddddddddd d%dZ0eej^e%e'feddddddddddd d&dZ0n|eej^e%e'feddddddddd d'dZ0eej^e%e'feddddddddd d(dZ0eej^e%e'f d)ddddddddddd d*dZ0d+dZ1ee2Z3ej\dkrd,d Z4e4ejj_6ddd!dd" d-d#Z7d.d$Z8y)/z7Provide an enhanced dataclass that performs validation.) annotationsN) TYPE_CHECKINGAnyCallableGenericLiteralNoReturnTypeVaroverload)warn) TypeGuarddataclass_transform)_config _decorators _mock_val_ser_namespace_utils _typing_extra) _dataclasses)getattr_migration) ConfigDict)PydanticUserError)Field FieldInfo PrivateAttr)PydanticDataclass)MappingNamespace) dataclassrebuild_dataclass_T )field_specifiersFT. initrepreqorder unsafe_hashfrozenconfigvalidate_on_initkw_onlyslotsc yNr%s h/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pydantic/dataclasses.pyrrs c yr1r2) _clsr&r'r(r)r*r+r,r-r.r/s r3rr0s#&r4r&r'r(r)r*r+r,r-cyr1r2r7s r3rrCs r4cyr1r2) r6r&r'r(r)r*r+r,r-s r3rrRs#&r4c  |dusJd|dusJdtjdk\r| d ni d  fd } || S| |S)a!!! abstract "Usage Documentation" [`dataclasses`](../concepts/dataclasses.md) 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 zddlm}||rtd|jdd|}t d|j D}|s.,t |d r td |jd td n t|d d}tj|}tjj|d}|j||j }t#j$|rNd}|f}t'|t(rt(|j*} || fz}t-j.|j|}/|j0r1td|jdtd n|j0xsdt3j4|} | D]@} t|| d} t7| t8s!t;|| t#j<| Bt#j>|5tAjB|fdd}ddd|jDrp|jFtIjJ|jFdfd } | jMd||_#r"t |dsdd}dd}||_'||_(d|_)||_*||_t|dd}|jV|_+tXjZdk\r|||_.||_.|j^|_/tatb|_2d|_3t#jh||d|S#1swY"xYw)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)codec3FK|]}tj|ywr1) dataclasses is_dataclass).0bases r3 z6dataclass..create_dataclass..s ZD!9!9$!? Zs!N__pydantic_config__z[`config` is set via both the `dataclass` decorator and `__pydantic_config__` for dataclass zK. The `config` specification from `dataclass` decorator will take priority.)category stacklevelT)replace_wrapped_methodszN`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.F)r&r'r(r)r*r+c<r |||St|}t||d}t|tr|j ||yt|t j r|jj||y|jj|||yr1) typegetattr isinstanceproperty__set__ functoolscached_property__dict__ __setitem____pydantic_validator__validate_assignment)instancenamevalueinst_clsattrfrozen_original_setattrs r3validated_setattrz>dataclass..create_dataclass..validated_setattrs+HdEBB>xt4dH-LL51i&?&?@%%11$>33GGRVX]^r4 __setstate__cztj|Dcgc]}t||jc}Scc}wr1)r?fieldsrKrV)selffs r3_dataclass_getstatez@dataclass..create_dataclass.._dataclass_getstates,;F;M;Md;STaGD!&&1TTTs8cttj||D]&\}}tj ||j |(yr1)zipr?r_object __setattr__rV)r`statefieldrWs r3_dataclass_setstatez@dataclass..create_dataclass.._dataclass_setstates?(+K,>,>t,De(LD u**4UCDr4__firstlineno__)r" ) raise_errors)rUrrVstrrWrreturnNone)r`rrn list[Any])r`rrgrprnro)5_internal._utilsr<r__name__any __bases__hasattrr UserWarningrKr ConfigWrapperrDecoratorInfosbuildupdate_from_config__doc___pydantic_dataclassesis_stdlib_dataclass issubclassr__parameters__types new_classr+rsafe_get_annotationsrLrsetattras_dataclass_fieldpatch_base_fieldsr?rrTrfrOwraps__get__ __getstate__r]__is_pydantic_dataclass____pydantic_decorators__ __module__sys version_inforj __qualname__ classmethod_pydantic_fields_complete__pydantic_fields_complete____pydantic_complete__complete_dataclass)clsr< original_clshas_dataclass_base config_dictconfig_wrapper decorators original_docbases generic_basecls_anns field_name field_valuer\rbri firstlinenorZr[r,r(r+kwargsr)r'r/r*s @@r3create_dataclassz#dataclass..create_dataclasssS 5 # #:3<<.Hjk)   ! ZCMM ZZ!f&8WSJ_=` mnqnznzm{|\]$  !' 2fEZ\`8a  ..{; //55cSW5X %%n5 {{ 4 4S 9 L FE#w'&s'9'9: ///#,,6C  G$$deheqeqdtumm( %++4uG!55c:" `J"#z48K+y1Z)>)Q)QR])^_  `# 4 4S 9 '' '  C   - -"  __S__ - _. _077cBCOWS.9UD$7 #6 )-%&0#" l,=tD %00   w &;+B,7L ("-C '44+67P+Q($)! 00nSXY S  s 2L00L:)r type[Any]rntype[PydanticDataclass])rr) r6r&r'r(r)r*r+r,r-r.r/rrs `````` ` @r3rrbsn^ 5=SSS= 5 (Y*YY ( 7"$u5^^@ $| G1A$1GGr4cVtd|jjDS)zReturn whether the fields were successfully collected (i.e. type hints were successfully resolved). This is a private helper, not meant to be used outside Pydantic. c34K|]}|jywr1) _complete)rA field_infos r3rCz,_pydantic_fields_complete..AsW z##Ws)all__pydantic_fields__values)rs r3rr<s$ Wc6M6M6T6T6VW WWr4)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)argsrs r3 _call_initvarrJs :;;r4rE)forcerl_parent_namespace_depth_types_namespacec|s |jrydD]B}||jvstt||tj r7t ||Dd|_||}n#|dkDrtj|dxsi}ni}tj|}tj|tj|jd||d 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`. N)__pydantic_core_schema__rS__pydantic_serializer__FrT) parent_depthr)parent_namespace)check)rl ns_resolver _force_build)rrQrLrKr MockValSerdelattrrparent_frame_namespacer NsResolverr|rrrwrD)rrrlrrrY rebuild_nsrs r3rrTs4 S..a 3<<  733E}G_G_(` C   !&C#% 1 $"99G^fjkqoq  "--#K ! 3 3 c55UC!   r4cl 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. rF)rQr?r@AttributeError)class_s r3is_pydantic_dataclassrs9*foo=b+BZBZ[aBbb s $' 33)r&Literal[False]r'boolr(rr)rr*rr+rr, ConfigDict | type[object] | Noner- bool | Noner.rr/rrn-Callable[[type[_T]], type[PydanticDataclass]])r6type[_T]r&rr'rr(rr)rr*rr+rr,rr-rr.rr/rrnr)r&rr'rr(rr)rr*rr+rr,rr-rrnr)r6rr&rr'rr(rr)rr*rr+rr,rr-rrnrr1)r6ztype[_T] | Noner&rr'rr(rr)rr*rr+rr,rr-rr.rr/rrnzGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass])rrrnr)rrrrrnr ) rrrrrlrrintrzMappingNamespace | Nonernr)rrrnz"TypeGuard[type[PydanticDataclass]])9r{ __future__r _annotationsr?rOrrtypingrrrrrr r r warningsr typing_extensionsr r _internalrrrrrrr| _migrationrr,rerrorsrr_rrr_internal._dataclassesr_internal._namespace_utilsr__all__r rrhrrrr __getattr__rInitVar__call__rrr2r4r3rs=2 ^^^<[[<)%119< * T]w;+<+