a
    Of"                     @  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	 ddlm
Z
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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% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ej,r<ddl-m.Z. G dd dej/Z0G dd de0ej/Z1neZ2d-ddddddd Z3d!d"d#d$d%dd%d&d'd(Z4d#d)d*d+d,Z5dS ).z0Private logic for creating pydantic dataclasses.    )annotationsN)partialwraps)AnyCallableClassVar)
ArgsKwargsSchemaSerializerSchemaValidatorcore_schema)	TypeGuard   )PydanticUndefinedAnnotation)	FieldInfo)PluggableSchemaValidatorcreate_schema_validator)PydanticDeprecatedSince20   )_config_decorators_typing_extra)collect_dataclass_fields)GenerateSchema)get_standard_typevars_map)set_dataclass_mocks)CallbackGetCoreSchemaHandler)generate_pydantic_signature)
ConfigDictc                   @  s8   e Zd ZU ded< ded< ded< dd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__objectNone)argskwargsreturnc                 O  s   d S N )selfr$   r%   r(   r(   X/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pydantic/_internal/_dataclasses.py__init__'   s    zStandardDataclass.__init__N)__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]Z__pydantic_complete__z ClassVar[core_schema.CoreSchema]__pydantic_core_schema__z$ClassVar[_decorators.DecoratorInfos]Z__pydantic_decorators__zClassVar[dict[str, FieldInfo]]__pydantic_fields__zClassVar[SchemaSerializer]__pydantic_serializer__z4ClassVar[SchemaValidator | PluggableSchemaValidator]__pydantic_validator__N)r,   r-   r.   __doc__r/   r(   r(   r(   r*   r0   *   s   
r0   ztype[StandardDataclass]zdict[str, Any] | Nonez_config.ConfigWrapper | Noner#   )clstypes_namespaceconfig_wrapperr&   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`.
        config_wrapper: The config wrapper instance, defaults to `None`.
    )typevars_mapr9   N)r   r   r3   )r7   r8   r9   r:   fieldsr(   r(   r*   set_dataclass_fieldsE   s    r<   T)raise_errorsz	type[Any]z_config.ConfigWrapperbool)r7   r9   r=   r8   r&   c             
     s  t | drtdt |du r(t| }t| ||d t| }t|||}t	| j
| j|dd}dddd	d
dd}| j d|_|| _
|j| _|| _t| dd}z6|r|| tt|jdd|dd}	n|j| dd}	W nF ty }
 z,|r t| | jd|
j d W Y d}
~
dS d}
~
0 0 || }z||	}	W n& |jy\   t| | jd Y dS 0 td| } |	| _t|	| | j| jd||j  | _! t"|	|| _#|j$rt%| j&dddd	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.
    Z__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be calledN)r9   T)initr;   r9   is_dataclassr0   r   r#   )__dataclass_self__r$   r%   r&   c                 _  s"   d}| }|j jt|||d d S )NT)Zself_instance)r5   Zvalidate_pythonr   )rA   r$   r%   Z__tracebackhide__sr(   r(   r*   r+      s    z$complete_dataclass.<locals>.__init__z	.__init__Z__get_pydantic_core_schema__F)Zfrom_dunder_get_core_schemaunpack)Zref_mode`zall referenced typesztype[PydanticDataclass]	dataclassstr)instancefieldvaluer&   c                  s     | || d S r'   )validate_assignment)rG   rH   rI   	validatorr(   r*   validated_setattr   s    z-complete_dataclass.<locals>.validated_setattr)(hasattrwarningswarnDeprecationWarningr   Zget_cls_types_namespacer<   r   r   r   r+   r3   r.   Zconfig_dictr1   __signature__getattrr   r   Zgenerate_schemar   r   r,   namecore_configZclean_schemaZCollectedInvalidtypingcastr2   r   r-   Zplugin_settingsr5   r	   r4   rJ   r   __setattr____get__)r7   r9   r=   r8   r:   Z
gen_schemasigr+   Zget_core_schemaZschemaerU   rM   r(   rK   r*   complete_dataclassW   st    

	

r\   z"TypeGuard[type[StandardDataclass]])_clsr&   c                 C  s2   t | o0t| d o0t| 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.
    r5   r/   )dataclassesr@   rN   setr   
issupersetrS   )r]   r(   r(   r*   is_builtin_dataclass   s
    

ra   )NN)6r6   
__future__r   Z_annotationsr^   rV   rO   	functoolsr   r   r   r   r   Zpydantic_corer   r	   r
   r   typing_extensionsr   errorsr   r;   r   Zplugin._schema_validatorr   r   r    r   r   r   _fieldsr   Z_generate_schemar   Z	_genericsr   Z_mock_val_serr   Z_schema_generation_sharedr   
_signaturer   TYPE_CHECKINGconfigr   Protocolr   r0   rQ   r<   r\   ra   r(   r(   r(   r*   <module>   s<     n