a
    “˜ëjJ  ã                   @  s  d Z ddlmZ ddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZ ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' e	rðddl(m)Z) ddl*m+Z+ dZ,edƒZ-ej.dk�r¬eej/e%e'fd�edddddddddddœ
ddddddddddddœdd„ƒƒZ0eej/e%e'fd�edddddddddddœ
d ddddddddddd!d"œd#d„ƒƒZ0n’eej/e%e'fd�eddddddddd$œdddddddddd%œ	d&d„ƒƒZ0eej/e%e'fd�eddddddddd$œd ddddddddd!d'œ
d(d„ƒƒZ0eej/e%e'fd�dAdddddddddddœ
d)ddddddddddd*d"œd+d„ƒZ0d!dd,œd-d.„Z1ee2ƒZ3ej.d/k �rÌd0d0d1d2œd3d4„Z4e4ej5_6ddd5dd6œd!ddd7d8dd9œd:d;„Z7d<d=d>œd?d@„Z8dS )Bz7Provide an enhanced dataclass that performs validation.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚCallableÚGenericÚLiteralÚNoReturnÚTypeVarÚoverload)Úwarn)Ú	TypeGuardÚdataclass_transformé   )Ú_configÚ_decoratorsÚ_mock_val_serÚ_namespace_utilsÚ_typing_extra)Ú_dataclasses)Úgetattr_migration)Ú
ConfigDict)ÚPydanticUserError)ÚFieldÚ	FieldInfoÚPrivateAttr)ÚPydanticDataclass)ÚMappingNamespace)Ú	dataclassÚrebuild_dataclassÚ_T©é   é
   )Zfield_specifiersFT.©
ÚinitÚreprÚeqÚorderÚunsafe_hashÚfrozenÚconfigÚvalidate_on_initÚkw_onlyÚslotszLiteral[False]Úboolz ConfigDict | type[object] | Nonezbool | Nonez-Callable[[type[_T]], type[PydanticDataclass]])r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   Úreturnc        
   
      C  s   d S ©N© r#   r1   r1   úS/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pydantic/dataclasses.pyr      s    r   ztype[_T]útype[PydanticDataclass])Ú_clsr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r/   c       
         C  s   d S r0   r1   )r4   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r1   r1   r2   r   0   s    ©r$   r%   r&   r'   r(   r)   r*   r+   )	r$   r%   r&   r'   r(   r)   r*   r+   r/   c                 C  s   d S r0   r1   r5   r1   r1   r2   r   C   s    )
r4   r$   r%   r&   r'   r(   r)   r*   r+   r/   c          	      C  s   d S r0   r1   )	r4   r$   r%   r&   r'   r(   r)   r*   r+   r1   r1   r2   r   R   s    ztype[_T] | NonezGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c       
      	     sp   |du sJ dƒ‚|dus J dƒ‚t jdkr6|	ˆdœ‰ni ‰dddœ‡ ‡‡‡‡‡‡‡fd	d
„}| du rh|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-   ú	type[Any]r3   ©Úclsr/   c              
     s°  ddl m} || ƒr*td| j› d�dd�‚| }tdd„ | jD ƒƒ}|spˆd	urpt| d
ƒrptd| j› d�tdd� ˆd	ur|ˆn
t	| d
d	ƒ}t
 |¡}tjj| dd�}| |¡ | j}t | ¡ròd	}| f}t| tƒrät| j }	||	f }t | j|¡} ˆd	u�r"ˆ‰ |j�r.td| j›d�tdd� n|j�p,d‰ t | ¡}
|
D ]0}t	| |d	ƒ}t|tƒ�r<t| |t |¡ƒ �q<t | ¡�0 t j!| fdˆˆˆˆ	ˆ dœˆ¤Ž} W d	  ƒ n1 �s°0    Y  |j"�r<| j#‰t$ %| j#¡dddddœ‡ ‡fdd„ƒ}| &d	| ¡| _#ˆ�r<t| dƒ�s<dddœdd „}dddd!œd"d#„}|| _'|| _(d| _)|| _*|| _t	|d$d	ƒ}|j+| _+t,j-d%k�r„|d	u�r„||_.|| _.|j/| _/t0t1ƒ| _2d| _3tj4| |dd&� | S )'zÃCreate 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 modelzdataclass-on-model)Úcodec                 s  s   | ]}t  |¡V  qd S r0   )ÚdataclassesÚis_dataclass)Ú.0Úbaser1   r1   r2   Ú	<genexpr>®   ó    z6dataclass.<locals>.create_dataclass.<locals>.<genexpr>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)Z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)   r   Ústrr   ÚNone)ÚinstanceÚnameÚvaluer/   c                  sl   ˆ rˆ| ||ƒS t | ƒ}t||d ƒ}t|tƒr<| | |¡ n,t|tjƒrX| j ||¡ n|j	 
| ||¡ d S r0   )ÚtypeÚgetattrÚ
isinstanceÚpropertyÚ__set__Ú	functoolsÚcached_propertyÚ__dict__Ú__setitem__Ú__pydantic_validator__Úvalidate_assignment)rG   rH   rI   Zinst_clsÚattr©Zfrozen_Zoriginal_setattrr1   r2   Úvalidated_setattrþ   s    
z>dataclass.<locals>.create_dataclass.<locals>.validated_setattrÚ__setstate__z	list[Any])Úselfr/   c                   s   ‡ fdd„t  ˆ ¡D ƒS )Nc                   s   g | ]}t ˆ |jƒ‘qS r1   )rK   rH   )r=   Úf©rY   r1   r2   Ú
<listcomp>  r@   zTdataclass.<locals>.create_dataclass.<locals>._dataclass_getstate.<locals>.<listcomp>)r;   Úfieldsr[   r1   r[   r2   Ú_dataclass_getstate  s    z@dataclass.<locals>.create_dataclass.<locals>._dataclass_getstate)rY   Ústater/   c                 S  s.   t t | ¡|ƒD ]\}}t | |j|¡ qd S r0   )Úzipr;   r]   ÚobjectÚ__setattr__rH   )rY   r_   ÚfieldrI   r1   r1   r2   Ú_dataclass_setstate  s    z@dataclass.<locals>.create_dataclass.<locals>._dataclass_setstateÚ__firstlineno__)r!   é   )Úraise_errors)5Z_internal._utilsr9   r   Ú__name__ÚanyÚ	__bases__Úhasattrr   ÚUserWarningrK   r   ÚConfigWrapperr   ZDecoratorInfosÚbuildZupdate_from_configÚ__doc__Ú_pydantic_dataclassesZis_stdlib_dataclassÚ
issubclassr   Ú__parameters__ÚtypesÚ	new_classr)   r   Zsafe_get_annotationsrL   r   ÚsetattrZas_dataclass_fieldZpatch_base_fieldsr;   r   rT   rb   rO   ÚwrapsÚ__get__Ú__getstate__rX   Ú__is_pydantic_dataclass__Z__pydantic_decorators__Ú
__module__ÚsysÚversion_infore   Ú__qualname__ÚclassmethodÚ_pydantic_fields_completeZ__pydantic_fields_complete__Ú__pydantic_complete__Úcomplete_dataclass)r8   r9   Zoriginal_clsZhas_dataclass_baseZconfig_dictZconfig_wrapperZ
decoratorsZoriginal_docÚbasesZgeneric_baseZcls_annsÚ
field_nameZfield_valuerW   r^   rd   Zfirstlineno©r*   r&   r)   Úkwargsr'   r%   r-   r(   rV   r2   Úcreate_dataclass™   s˜    	þü






ü
ÿø	÷&

z#dataclass.<locals>.create_dataclassN)r{   r|   )r4   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r†   r1   r„   r2   r   b   s    /
" !r7   c                 C  s   t dd„ | j ¡ D ƒƒS )z®Return 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.
    c                 s  s   | ]}|j V  qd S r0   )Z	_complete)r=   Z
field_infor1   r1   r2   r?   A  r@   z,_pydantic_fields_complete.<locals>.<genexpr>)ÚallZ__pydantic_fields__Úvalues)r8   r1   r1   r2   r   <  s    r   )r!   é   r   r   )Úargsr…   r/   c                  O  s   t dƒ‚dS )a9  This 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[<parameter>]`.
        z 'InitVar' object is not callableN)Ú	TypeError)rŠ   r…   r1   r1   r2   Ú_call_initvarJ  s    rŒ   rB   )Úforcerg   Ú_parent_namespace_depthÚ_types_namespaceÚintzMappingNamespace | None)r8   r�   rg   rŽ   r�   r/   c                C  sž   |s| j rdS dD ]*}|| jv rtt| |ƒtjƒst| |ƒ qd| _ |durR|}n |dkrntj|dd�pji }ni }t	j
|d�}tj| tj| jdd�||dd	�S )
ax  Try 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)Z__pydantic_core_schema__rS   Z__pydantic_serializer__Fr   T)Zparent_depthr�   )Zparent_namespace)Úcheck)rg   Úns_resolverZ_force_build)r€   rQ   rL   rK   r   Z
MockValSerÚdelattrr   Zparent_frame_namespacer   Z
NsResolverrp   r�   r   rm   rA   )r8   r�   rg   rŽ   r�   rU   Z
rebuild_nsr’   r1   r1   r2   r   T  s*    
ÿ÷r   r6   z"TypeGuard[type[PydanticDataclass]])Úclass_r/   c                C  s0   zd| j v ot | ¡W S  ty*   Y dS 0 dS )z©Whether a class is a pydantic dataclass.

    Args:
        class_: The class.

    Returns:
        `True` if the class is a pydantic dataclass, `False` otherwise.
    ry   FN)rQ   r;   r<   ÚAttributeError)r”   r1   r1   r2   Úis_pydantic_dataclass‘  s    	r–   )N)9ro   Ú
__future__r   Z_annotationsr;   rO   r{   rs   Útypingr   r   r   r   r   r   r	   r
   Úwarningsr   Ztyping_extensionsr   r   Ú	_internalr   r   r   r   r   r   rp   Z
_migrationr   r*   r   Úerrorsr   r]   r   r   r   Z_internal._dataclassesr   Z_internal._namespace_utilsr   Ú__all__r   r|   rc   r   r   rh   Ú__getattr__rŒ   ZInitVarÚ__call__r   r–   r1   r1   r1   r2   Ú<module>   s¼   (õ*ô.÷&ö( ÿô* Zú=