o
    h)                     @  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
 ddlmZmZ ddlmZ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 ddlm Z m!Z!m"Z" ddl m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ej1rd	dl2m3Z3 G dd dej4Z5G dd de5ej4Z6neZ7d;d<d"d#Z8d$d%d=d+d,Z9d>d/d0Z:d?d5d6Z;d@d9d:Z<dS )Az0Private logic for creating pydantic dataclasses.    )annotationsN)partialwraps)	Parameter	Signature)AnyCallableClassVar)
ArgsKwargsPydanticUndefinedSchemaSerializerSchemaValidatorcore_schema)	TypeGuard   )PydanticUndefinedAnnotation)	FieldInfo)create_schema_validator)PydanticDeprecatedSince20   )_config_decorators_typing_extra)ConfigWrapper)collect_dataclass_fields)GenerateSchemagenerate_pydantic_signature)get_standard_typevars_map)set_dataclass_mocks)CallbackGetCoreSchemaHandler)is_valid_identifier)
ConfigDictc                   @  s0   e Zd ZU ded< ded< ded< dddZdS )StandardDataclasszClassVar[dict[str, Any]]__dataclass_fields__zClassVar[Any]__dataclass_params__zClassVar[Callable[..., None]]__post_init__argsobjectkwargsreturnNonec                 O  s   d S N )selfr&   r(   r,   r,   U/var/www/html/ai/venv/lib/python3.10/site-packages/pydantic/_internal/_dataclasses.py__init__*   s   zStandardDataclass.__init__N)r&   r'   r(   r'   r)   r*   )__name__
__module____qualname____annotations__r/   r,   r,   r,   r.   r"   %   s
   
 r"   c                   @  sJ   e Zd ZU dZded< ded< ded< ded	< d
ed< ded< ded< dS )PydanticDataclassai  A protocol containing attributes only available once a class has been decorated as a Pydantic dataclass.

        Attributes:
            __pydantic_config__: Pydantic-specific configuration settings for the dataclass.
            __pydantic_complete__: Whether dataclass building is completed, or if there are still undefined fields.
            __pydantic_core_schema__: The pydantic-core schema used to build the SchemaValidator and SchemaSerializer.
            __pydantic_decorators__: Metadata containing the decorators defined on the dataclass.
            __pydantic_fields__: Metadata about the fields defined on the dataclass.
            __pydantic_serializer__: The pydantic-core SchemaSerializer used to dump instances of the dataclass.
            __pydantic_validator__: The pydantic-core SchemaValidator used to validate instances of the dataclass.
        zClassVar[ConfigDict]__pydantic_config__zClassVar[bool]__pydantic_complete__z ClassVar[core_schema.CoreSchema]__pydantic_core_schema__z$ClassVar[_decorators.DecoratorInfos]__pydantic_decorators__zClassVar[dict[str, FieldInfo]]__pydantic_fields__zClassVar[SchemaSerializer]__pydantic_serializer__zClassVar[SchemaValidator]__pydantic_validator__N)r0   r1   r2   __doc__r3   r,   r,   r,   r.   r4   -   s   
 r4   clstype[StandardDataclass]types_namespacedict[str, Any] | Noner)   r*   c                 C  s    t | }t| ||d}|| _dS )zCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        types_namespace: The types namespace, defaults to `None`.
    )typevars_mapN)r   r   r9   )r=   r?   rA   fieldsr,   r,   r.   set_dataclass_fieldsH   s   
rC   T)raise_errors	type[Any]config_wrapper_config.ConfigWrapperrD   boolc             
     s  t | drtdt |du rt| }t| | t| }t|||}t	| | j
|}ddd}| j d|_|| _|j| _|| _t| dd}z|rY|| tt|jdd|dd}	n|j| dd}	W n" ty }
 z|rl t| | jd|
j d W Y d}
~
dS d}
~
ww || }z||	}	W n |jy   t| | jd Y dS w td| } |	| _t|	| | j| jd||j  | _! t"|	|| _#|j$rt%| j&d fdd}|'d| | _&dS ) a  Finish building a pydantic dataclass.

    This logic is called on a class which has already been wrapped in `dataclasses.dataclass()`.

    This is somewhat analogous to `pydantic._internal._model_construction.complete_model_class`.

    Args:
        cls: The class.
        config_wrapper: The config wrapper instance.
        raise_errors: Whether to raise errors, defaults to `True`.
        types_namespace: The types namespace.

    Returns:
        `True` if building a pydantic dataclass is successfully completed, `False` otherwise.

    Raises:
        PydanticUndefinedAnnotation: If `raise_error` is `True` and there is an undefined annotations.
    __post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be calledN__dataclass_self__r4   r&   r   r(   r)   r*   c                 _  s"   d}| }|j jt|||d d S )NT)self_instance)r;   validate_pythonr
   )rJ   r&   r(   __tracebackhide__sr,   r,   r.   r/      s   z$complete_dataclass.<locals>.__init__z	.__init____get_pydantic_core_schema__F)from_dunder_get_core_schemaunpack)ref_mode`zall referenced typesztype[PydanticDataclass]	dataclassinstance__fieldstr__valuec                   s     | || d S r+   )validate_assignment)rU   rV   rX   	validatorr,   r.   validated_setattr   s   z-complete_dataclass.<locals>.validated_setattrT)rJ   r4   r&   r   r(   r   r)   r*   )rU   r   rV   rW   rX   rW   r)   r*   )(hasattrwarningswarnDeprecationWarningr   get_cls_types_namespacerC   r   r   generate_dataclass_signaturer9   r2   r/   config_dictr5   __signature__getattrr   r   generate_schemar   r   r0   namecore_configclean_schemaCollectedInvalidtypingcastr7   r   r1   plugin_settingsr;   r   r:   rY   r   __setattr____get__)r=   rF   rD   r?   rA   
gen_schemasigr/   get_core_schemaschemaerh   r\   r,   rZ   r.   complete_dataclassU   sr   



	

ru   paramr   c                 C  s   | j }t|trQ| j}|dkrt}| j}|j}|j}|du r*t|tr*t	|r*|}nt|tr5t	|r5|}|j }|t
u rI|jt
u rFtjj}ntj}| j|||dS | S )zCustom processing where the parameter default is of type FieldInfo

    Args:
        param (Parameter): The parameter

    Returns:
        Parameter: The custom processed parameter
    r   N)
annotationrg   default)rx   
isinstancer   rw   r   rg   aliasvalidation_aliasrW   r    r   default_factoryinspectr   emptydataclasses_HAS_DEFAULT_FACTORYreplace)rv   param_defaultrw   rg   rz   r{   rx   r,   r,   r.   process_param_defaults   s&   	


r   rB   dict[str, FieldInfo]r   r   c                 C  s   t | j||tdS )zGenerate signature for a pydantic dataclass.

    Args:
        cls: The dataclass.
        fields: The model fields.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass signature.
    )initrB   rF   post_process_parameter)r   r/   r   )r=   rB   rF   r,   r,   r.   rb      s   
rb   _cls"TypeGuard[type[StandardDataclass]]c                 C  s2   t | ot| d ot| jtt| di S )a>  Returns True if a class is a stdlib dataclass and *not* a pydantic dataclass.

    We check that
    - `_cls` is a dataclass
    - `_cls` does not inherit from a processed pydantic dataclass (and thus have a `__pydantic_validator__`)
    - `_cls` does not have any annotations that are not dataclass fields
    e.g.
    ```py
    import dataclasses

    import pydantic.dataclasses

    @dataclasses.dataclass
    class A:
        x: int

    @pydantic.dataclasses.dataclass
    class B(A):
        y: int
    ```
    In this case, when we first check `B`, we make an extra check and look at the annotations ('y'),
    which won't be a superset of all the dataclass fields (only the stdlib fields i.e. 'x')

    Args:
        cls: The class.

    Returns:
        `True` if the class is a stdlib dataclass, `False` otherwise.
    r;   r3   )r   is_dataclassr]   setr#   
issupersetre   )r   r,   r,   r.   is_builtin_dataclass   s
   

r   r+   )r=   r>   r?   r@   r)   r*   )
r=   rE   rF   rG   rD   rH   r?   r@   r)   rH   )rv   r   r)   r   )r=   r>   rB   r   rF   r   r)   r   )r   rE   r)   r   )=r<   
__future__r   _annotationsr   r}   rk   r^   	functoolsr   r   r   r   r   r   r	   pydantic_corer
   r   r   r   r   typing_extensionsr   errorsr   rB   r   plugin._schema_validatorr   r    r   r   r   r   _fieldsr   _generate_schemar   r   	_genericsr   _mock_val_serr   _schema_generation_sharedr   _utilsr    TYPE_CHECKINGconfigr!   Protocolr"   r4   r`   rC   ru   r   rb   r   r,   r,   r,   r.   <module>   sD    
i
'