U
    PÈÞfV9  ã                   @  sê  d Z ddlm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 ddlmZ ddlmZmZmZ ddl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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„ƒƒZ+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"d„ƒƒZ+n’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„ƒƒZ+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„ƒƒZ+eej*e"e$f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!œd*d„ƒZ+ee,ƒZ-d+ej)  k�r”d,k �r²n nd-d-d.d/œd0d1„Z.e.ej/_0ddd2dd3œd ddd4d5dd6œd7d8„Z1d9d:d;œd<d=„Z2dS )?z7Provide an enhanced dataclass that performs validation.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚCallableÚGenericÚNoReturnÚTypeVarÚoverload)Úwarn)ÚLiteralÚ	TypeGuardÚdataclass_transformé   )Ú_configÚ_decoratorsÚ_typing_extra)Ú_dataclasses)Úgetattr_migration)Ú
ConfigDict)ÚPydanticUserError)ÚFieldÚ	FieldInfoÚPrivateAttr)ÚPydanticDataclass)Ú	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    r.   r.   úN/var/www/html/chatgpt/venv/lib/python3.8/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 r-   r.   )r1   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r.   r.   r/   r   .   s    ©r!   r"   r#   r$   r%   r&   r'   r(   )	r!   r"   r#   r$   r%   r&   r'   r(   r,   c                 C  s   d S r-   r.   r2   r.   r.   r/   r   A   s    )
r1   r!   r"   r#   r$   r%   r&   r'   r(   r,   c          	      C  s   d S r-   r.   )	r1   r!   r"   r#   r$   r%   r&   r'   r(   r.   r.   r/   r   P   s    ztype[_T] | NonezGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c       
      	     s€   |dkst dƒ‚|dk	s t dƒ‚tjdkr6|	|
dœ‰ni ‰dddœd	d
„‰dddœ‡ ‡‡‡‡‡‡‡fdd„}| dkrx|S || ƒS )aÃ  Usage 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*   ú	type[Any]ÚNone)Úclsr,   c                 S  sª   | j D ]ž}t|dg ƒ}|D ]ˆ}t| |dƒ}t|tƒs6qd|i}tjdkrV|jrVd|d< |jdk	rj|j|d< t| |t	j
f |Žƒ | j d¡dkr”i | _|| | j|< qqdS )a  Make 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__NÚdefaultr   Tr)   r"   )Ú__mro__ÚgetattrÚ
isinstancer   ÚsysÚversion_infor)   r"   ÚsetattrÚdataclassesÚfieldÚ__dict__Úgetr6   )r5   Zannotation_clsr   Ú
field_nameZfield_valueZ
field_argsr.   r.   r/   Úmake_pydantic_fields_compatible–   s    



z2dataclass.<locals>.make_pydantic_fields_compatibler0   c           
   	     s8  ddl m} || ƒr*td| j› d�dd�‚| }ˆ dk	r:ˆ n
t| ddƒ}t |¡}tj 	| ¡}| j
}t | ¡r¢d}| f}t| tƒr”t| j }||f }t | j|¡} ˆ| ƒ ˆdk	rÖˆ}	|jràtd	| j›d
�tdd� n
|jpÞd}	tj| fdˆˆˆˆ|	dœˆ—Ž} || _|| _
|j| _|j| _d| _tj| |d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)Ú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_errorsÚtypes_namespace)Z_internal._utilsrD   r   Ú__name__r9   r   ÚConfigWrapperr   ZDecoratorInfosÚbuildÚ__doc__Ú_pydantic_dataclassesZis_builtin_dataclassÚ
issubclassr   Ú__parameters__ÚtypesÚ	new_classr&   r
   ÚUserWarningr>   r   Z__pydantic_decorators__Ú
__module__Ú__qualname__Ú__pydantic_complete__Úcomplete_dataclass)
r5   rD   Zoriginal_clsZconfig_dictZconfig_wrapperZ
decoratorsZoriginal_docÚbasesZgeneric_baseZfrozen_©r'   r#   r&   ÚkwargsrC   r$   r"   r%   r.   r/   Úcreate_dataclass¹   s^    	þ




ü
ÿø	÷z#dataclass.<locals>.create_dataclassN)ÚAssertionErrorr;   r<   )r1   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r^   r.   r\   r/   r   `   s    .
#"O)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)rb   r]   r.   r.   r/   Ú_call_initvar  s    rd   rG   )ÚforcerK   Ú_parent_namespace_depthÚ_types_namespaceÚintzdict[str, Any] | None)r5   re   rK   rf   rg   r,   c                C  sp   |s| j rdS |dk	r | ¡ }n.|dkr>tj|d�p6i }|}ni }t | |¡}tj| tj| j	dd�||d�S 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`.
    Nr   )Zparent_depthF)ÚcheckrJ   )
rY   Úcopyr   Zparent_frame_namespaceZmerge_cls_and_parent_nsrQ   rZ   r   rN   rF   )r5   re   rK   rf   rg   rL   Zframe_parent_nsr.   r.   r/   r     s    

ür   r3   z"TypeGuard[type[PydanticDataclass]])Úclass_r,   c                C  s2   zd| j kot | ¡W S  tk
r,   Y dS X 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.
    Z__pydantic_validator__FN)r@   r>   Úis_dataclassÚAttributeError)rk   r.   r.   r/   Úis_pydantic_dataclassL  s    	rn   )N)3rP   Ú
__future__r   Z_annotationsr>   r;   rT   Útypingr   r   r   r   r   r   r	   Úwarningsr
   Ztyping_extensionsr   r   r   Ú	_internalr   r   r   r   rQ   Z
_migrationr   r'   r   Úerrorsr   Úfieldsr   r   r   Z_internal._dataclassesr   Ú__all__r   r<   r?   r   rM   Ú__getattr__rd   ÚInitVarÚ__call__r   rn   r.   r.   r.   r/   Ú<module>   s¶   $õ*ô.÷&ö( ÿô* +ú1