o
    ¨ÝjöG  ã                   @  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	 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 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ej/e&e(fd�edddddddddddœ
dJd(d)„ƒƒZ0eej/e&e(fd�edddddddddddœ
dKd-d)„ƒƒZ0eej/e&e(fd�	dLdddddddddddœ
dMd0d)„ƒZ0dNd2d3„Z1e e2ƒZ3ej4d4k rídOd9d:„Z5e5ej6_7ddd;dd<œdPdCdD„Z8dQdHdI„Z9dS )Rz7Provide an enhanced dataclass that performs validation.é    )ÚannotationsN)ÚCallable)ÚTYPE_CHECKINGÚAnyÚGenericÚLiteralÚNoReturnÚ	TypeGuardÚTypeVarÚoverload)Úwarn)Ú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Úslotsr!   úLiteral[False]r"   Úboolr#   r$   r%   r&   r'   ú ConfigDict | type[object] | Noner(   úbool | Noner)   r*   Úreturnú-Callable[[type[_T]], type[PydanticDataclass]]c        
   
      C  ó   d S ©N© r    r3   r3   úO/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/dataclasses.pyr      ó   r   Ú_clsútype[_T]útype[PydanticDataclass]c       
         C  r1   r2   r3   )r6   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r3   r3   r4   r   1   r5   útype[_T] | NoneúGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c       
      	     sP   |du sJ dƒ‚|dusJ dƒ‚d‡ ‡‡‡‡‡‡‡fdd	„}| d
u r$|S || ƒS )ux	  !!! 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 decorator should be used similarly to the [`@dataclasses.dataclass`][dataclasses.dataclass] decorator.

    A Pydantic dataclass validates its inputs like a `BaseModel` does. Its
    [`ValidationError`][pydantic_core.ValidationError] includes each rejected value, while
    [Logfire](../integrations/logfire.md) can retain the complete validation input and surrounding trace
    context â€” see [Troubleshooting validation errors](../errors/troubleshooting.md).

    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 supportedÚclsú	type[Any]r/   r8   c                   sˆ  ddl m} || ƒrtd| j› d�dd�‚| }tdd„ | jD ƒƒ}|s8ˆd	ur8t| d
ƒr8td| j› d�tdd� ˆd	ur>ˆnt	| d
d	ƒ}t
 |¡}tjj| dd�}| |¡ | j}t | ¡ryd	}| f}t| tƒrrt| j }	||	f }t | j|¡} ˆd	ur�ˆ‰ |jrŽtd| j›d�tdd� n|jp“d‰ t | ¡}
|
D ]}t	| |d	ƒ}t|tƒr±t| |t |¡ƒ q›t | ¡� t j!| dˆˆˆˆ	ˆ ˆˆd�	} W d	  ƒ n1 sÐw   Y  |j"�r
| j#‰t$ %| j#¡d*‡ ‡fdd„ƒ}| &d	| ¡| _#ˆ�r
t| dƒ�s
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 r2   )ÚdataclassesÚis_dataclass)Ú.0Úbaser3   r3   r4   Ú	<genexpr>�   s   € 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)   r*   Úinstancer   ÚnameÚstrÚvaluer   r/   ÚNonec                  sp   ˆ rˆ| ||ƒS t | ƒ}t||d ƒ}t|tƒr| | |¡ d S t|tjƒr.| j ||¡ d S |j	 
| ||¡ d S r2   )ÚtypeÚgetattrÚ
isinstanceÚpropertyÚ__set__Ú	functoolsÚcached_propertyÚ__dict__Ú__setitem__Ú__pydantic_validator__Úvalidate_assignment)rH   rI   rK   Zinst_clsÚattr©Zfrozen_Zoriginal_setattrr3   r4   Úvalidated_setattrÞ   s   
z>dataclass.<locals>.create_dataclass.<locals>.validated_setattrÚ__setstate__Úselfú	list[Any]c                   s   ‡ fdd„t  ˆ ¡D ƒS )Nc                   s   g | ]}t ˆ |jƒ‘qS r3   )rN   rI   )rA   Úf©r\   r3   r4   Ú
<listcomp>ú   s    zTdataclass.<locals>.create_dataclass.<locals>._dataclass_getstate.<locals>.<listcomp>)r?   Úfieldsr_   r3   r_   r4   Ú_dataclass_getstateù   s   z@dataclass.<locals>.create_dataclass.<locals>._dataclass_getstateÚstatec                 S  s2   t t | ¡|dd�D ]\}}t | |j|¡ q
d S )NT)Ústrict)Úzipr?   ra   ÚobjectÚ__setattr__rI   )r\   rc   ÚfieldrK   r3   r3   r4   Ú_dataclass_setstateü   s   ÿz@dataclass.<locals>.create_dataclass.<locals>._dataclass_setstateÚ__firstlineno__)é   é   )Úraise_errors)rH   r   rI   rJ   rK   r   r/   rL   )r\   r   r/   r]   )r\   r   rc   r]   r/   rL   )5Z_internal._utilsr=   r   Ú__name__ÚanyÚ	__bases__Úhasattrr   ÚUserWarningrN   r   ÚConfigWrapperr   ZDecoratorInfosÚbuildZupdate_from_configÚ__doc__Ú_pydantic_dataclassesZis_stdlib_dataclassÚ
issubclassr   Ú__parameters__ÚtypesÚ	new_classr&   r   Zsafe_get_annotationsrO   r   ÚsetattrZas_dataclass_fieldZpatch_base_fieldsr?   r   rW   rg   rR   ÚwrapsÚ__get__Ú__getstate__r[   Ú__is_pydantic_dataclass__Z__pydantic_decorators__Ú
__module__ÚsysÚversion_inforj   Ú__qualname__ÚclassmethodÚ_pydantic_fields_completeZ__pydantic_fields_complete__Ú__pydantic_complete__Úcomplete_dataclass)r;   r=   Zoriginal_clsZhas_dataclass_baseZconfig_dictZconfig_wrapperZ
decoratorsZoriginal_docÚbasesZgeneric_baseZcls_annsÚ
field_nameZfield_valuerZ   rb   ri   Zfirstlineno©r'   r#   r&   r)   r$   r"   r*   r%   rY   r4   Úcreate_dataclassx   sœ   	þü





ü€


€öÿ



z#dataclass.<locals>.create_dataclassN)r;   r<   r/   r8   r3   )r6   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r‹   r3   rŠ   r4   r   A   s
   4 "r;   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 r2   )Z	_complete)rA   Z
field_infor3   r3   r4   rC   !  s   € z,_pydantic_fields_complete.<locals>.<genexpr>)ÚallZ__pydantic_fields__Úvalues)r;   r3   r3   r4   r…     s   r…   )rk   é   Úargsr   Úkwargsr   c                  O  s   t dƒ‚)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 callable)Ú	TypeError)r�   r�   r3   r3   r4   Ú_call_initvar*  s   r’   rE   )Úforcerm   Ú_parent_namespace_depthÚ_types_namespacer“   rm   r”   Úintr•   úMappingNamespace | Nonec                C  s¤   |s| j rdS dD ]}|| jv r!tt| |ƒtjtjfƒs!t| |ƒ q	d| _ |dur,|}n|dkr:tj	|dd�p8i }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__rV   Z__pydantic_serializer__Fr   T)Zparent_depthr“   )Zparent_namespace)Úcheck)rm   Úns_resolverZ_force_build)r†   rT   rO   rN   r   ZMockCoreSchemaZ
MockValSerÚdelattrr   Zparent_frame_namespacer   Z
NsResolverrv   r‡   r   rs   rD   )r;   r“   rm   r”   r•   rX   Z
rebuild_nsr™   r3   r3   r4   r   4  s0   
ÿ
€ÿ÷r   Úclass_r<   ú"TypeGuard[type[PydanticDataclass]]c                C  s,   zd| j v o
t | ¡W S  ty   Y dS w )z©Whether a class is a pydantic dataclass.

    Args:
        class_: The class.

    Returns:
        `True` if the class is a pydantic dataclass, `False` otherwise.
    r   F)rT   r?   r@   ÚAttributeError)r›   r3   r3   r4   Úis_pydantic_dataclassu  s
   	ÿrž   )r!   r+   r"   r,   r#   r,   r$   r,   r%   r,   r&   r,   r'   r-   r(   r.   r)   r,   r*   r,   r/   r0   )r6   r7   r!   r+   r"   r,   r#   r,   r$   r,   r%   r,   r&   r.   r'   r-   r(   r.   r)   r,   r*   r,   r/   r8   r2   )r6   r9   r!   r+   r"   r,   r#   r,   r$   r,   r%   r,   r&   r.   r'   r-   r(   r.   r)   r,   r*   r,   r/   r:   )r;   r8   r/   r,   )r�   r   r�   r   r/   r   )r;   r8   r“   r,   rm   r,   r”   r–   r•   r—   r/   r.   )r›   r<   r/   rœ   ):ru   Ú
__future__r   Z_annotationsr?   rR   r�   ry   Úcollections.abcr   Útypingr   r   r   r   r   r	   r
   r   Úwarningsr   Ztyping_extensionsr   Ú	_internalr   r   r   r   r   r   rv   Z
_migrationr   r'   r   Úerrorsr   ra   r   r   r   Z_internal._dataclassesr   Z_internal._namespace_utilsr   Ú__all__r   rh   r   r…   rn   Ú__getattr__r‚   r’   ÚInitVarÚ__call__r   rž   r3   r3   r3   r4   Ú<module>   s’    (õôÿô 
[

úA