a
    hA                     @  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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 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rddl&m'Z' ddl(m)Z) dZ*edZ+ej,dkre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.ne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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Z.d!dd,d-d.Z/ee0Z1ej,d/k rd0d0d1d2d3d4Z2e2ej3_4ddd5dd6d!ddd7d8dd9d:d;Z5d<d=d>d?d@Z6dS )Bz7Provide an enhanced dataclass that performs validation.    )annotationsN)TYPE_CHECKINGAnyCallableGenericLiteralNoReturnTypeVaroverload)warn)	TypeGuarddataclass_transform   )_config_decorators_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"   r0   r0   P/var/www/html/assistant/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 r/   r0   )r3   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r0   r0   r1   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/   r0   r4   r0   r0   r1   r   B   s    )
r3   r#   r$   r%   r&   r'   r(   r)   r*   r.   c          	      C  s   d S r/   r0   )	r3   r#   r$   r%   r&   r'   r(   r)   r*   r0   r0   r1   r   Q   s    ztype[_T] | NonezGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c       
      	     s   |du sJ d|dus J dt jdkr6|	|
dni dddd	d
ddd fdd}| du rx|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]Noneclsr.   c              	   S  s   | j D ]}t|di }|D ]}t| |d}t|ts6qd|i}tjdkrV|jrVd|d< |jdurj|j|d< t| |t	j
f i | | jddu ri | _|| | 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__getr9   )r8   Zannotation_clsr   
field_nameZfield_valueZ
field_argsr0   r0   r1   make_pydantic_fields_compatible   s    



z2dataclass.<locals>.make_pydantic_fields_compatibler2   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}t| rd	}| f}t| trt| j }	||	f }t| j|} |  d	ur}
|jr(td| jdtdd n|jp&d}
tj| fd|
d} d| _|| _|| _|j| _|j| _tt| _ d| _!tj"| |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 modelzdataclass-on-model)codec                 s  s   | ]}t |V  qd S r/   )rA   is_dataclass).0baser0   r0   r1   	<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
stacklevelzN`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.FT)r#   r$   r%   r&   r'   r(   )raise_errors)#Z_internal._utilsrG   r   __name__any	__bases__hasattrr   UserWarningr<   r   ConfigWrapperr   ZDecoratorInfosbuild__doc___pydantic_dataclassesZis_builtin_dataclass
issubclassr   __parameters__types	new_classr(   rA   r   __is_pydantic_dataclass__Z__pydantic_decorators__
__module____qualname__classmethod_pydantic_fields_completeZ__pydantic_fields_complete____pydantic_complete__complete_dataclass)r8   rG   Zoriginal_clsZhas_dataclass_baseZconfig_dictZconfig_wrapperZ
decoratorsZoriginal_docbasesZgeneric_baseZfrozen_r)   r%   r(   kwargsrF   r&   r$   r'   r0   r1   create_dataclass   sp    	





	
z#dataclass.<locals>.create_dataclassN)r>   r?   )r3   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   rj   r0   rh   r1   r   a   s    /
!"br7   c                 C  s   t dd | j D S )zReturn whether the fields where successfully collected (i.e. type hints were successfully resolves).

    This is a private property, not meant to be used outside Pydantic.
    c                 s  s   | ]}|j V  qd S r/   )Z	_complete)rJ   Z
field_infor0   r0   r1   rL   #  rM   z,_pydantic_fields_complete.<locals>.<genexpr>)allZ__pydantic_fields__values)r8   r0   r0   r1   rd     s    rd   )r       r   r   )argsri   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)rn   ri   r0   r0   r1   _call_initvar,  s    rp   rO   )forcerR   _parent_namespace_depth_types_namespaceintzMappingNamespace | None)r8   rq   rR   rr   rs   r.   c                C  s   |s| j rdS dD ]}|| jv rt| | qd| _ |dur@|}n |dkr\tj|ddpXi }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__Z__pydantic_validator__Z__pydantic_serializer__Fr   T)Zparent_depthrq   )Zparent_namespace)check)rR   ns_resolverZ_force_build)re   rC   delattrr   Zparent_frame_namespacer   Z
NsResolverr[   rf   r   rX   rN   )r8   rq   rR   rr   rs   attrZ
rebuild_nsrv   r0   r0   r1   r   6  s*    

r   r5   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 )zWhether a class is a pydantic dataclass.

    Args:
        class_: The class.

    Returns:
        `True` if the class is a pydantic dataclass, `False` otherwise.
    r`   FN)rC   rA   rI   AttributeError)ry   r0   r0   r1   is_pydantic_dataclasss  s    	r{   )N)7rZ   
__future__r   Z_annotationsrA   r>   r^   typingr   r   r   r   r   r   r	   r
   warningsr   Ztyping_extensionsr   r   	_internalr   r   r   r   r   r[   Z
_migrationr   r)   r   errorsr   fieldsr   r   r   Z_internal._dataclassesr   Z_internal._namespace_utilsr   __all__r   r?   rB   r   rd   rS   __getattr__rp   ZInitVar__call__r   r{   r0   r0   r0   r1   <module>   s   (*.&( * ==