o
    ¨ÝjH5  ã                   @  sÆ  U 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 ddlmZ ddlmZmZmZ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& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 er²ddl6m7Z8 d
dl9m:Z: G dd„ de8eƒZ;	d<d=d$d%„Z<d&dd'd(œd>d-d.„Z=d?d0d1„Z>d@d5d6„Z?e@eAejBe f ZCd7eDd8< edAd:d;„ƒZEdS )Bz0Private logic for creating pydantic dataclasses.é    )ÚannotationsN)Ú	Generator)Úcontextmanager)Úpartial)ÚTYPE_CHECKINGÚAnyÚClassVarÚProtocolÚ	TypeAliasÚcast)Ú
ArgsKwargsÚSchemaSerializerÚSchemaValidatorÚcore_schema)ÚTypeIsé   )ÚPydanticUndefinedAnnotation)Ú	FieldInfo)ÚPluggableSchemaValidatorÚcreate_schema_validator)ÚPydanticDeprecatedSince20é   )Ú_configÚ_decorators)Úcollect_dataclass_fields)ÚGenerateSchemaÚInvalidSchemaError)Úget_standard_typevars_map)Úset_dataclass_mocks)Ú
NsResolver)Úgenerate_pydantic_signature)ÚLazyClassAttribute)ÚDataclassInstance)Ú
ConfigDictc                   @  sX   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< eddd„ƒZ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]Z__pydantic_decorators__zClassVar[dict[str, FieldInfo]]Ú__pydantic_fields__zClassVar[SchemaSerializer]Ú__pydantic_serializer__z4ClassVar[SchemaValidator | PluggableSchemaValidator]Ú__pydantic_validator__ÚreturnÚboolc                 C  s   d S ©N© ©Úclsr.   r.   úZ/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/_internal/_dataclasses.pyÚ__pydantic_fields_complete__=   s   z.PydanticDataclass.__pydantic_fields_complete__N)r+   r,   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__Úclassmethodr2   r.   r.   r.   r1   r$   (   s   
 r$   r0   útype[StandardDataclass]Úconfig_wrapperú_config.ConfigWrapperÚns_resolverúNsResolver | Noner+   ÚNonec                 C  s"   t | ƒ}t| |||d�}|| _dS )zÚCollect and set `cls.__pydantic_fields__`.

    Args:
        cls: The class.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
    )r<   Útypevars_mapr:   N)r   r   r(   )r0   r:   r<   r?   Úfieldsr.   r.   r1   Úset_dataclass_fieldsA   s
   ÿ
rA   TF)Úraise_errorsr<   Ú_force_buildú	type[Any]rB   r,   rC   c             
   C  sx  | j }ddd	„}| j› d
�|_|| _ |j| _t| ||d� |s(|jr(t| ƒ dS t| dƒr3t 	dt
¡ t| ƒ}t|||d�}tdtt|| j|j|jdd�ƒ| _z| | ¡}	W n' ty} }
 z|ra‚ t| |
jdurod|
j› d�ndƒ W Y d}
~
dS d}
~
ww |j| jd�}z| |	¡}	W n tyš   t| ƒ Y dS w td| ƒ} |	| _t|	| | j| jd||jƒ| _ t!|	|ƒ| _"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`.
        ns_resolver: The namespace resolver instance to use when collecting dataclass fields
            and during schema building.
        _force_build: Whether to force building the dataclass, no matter if
            [`defer_build`][pydantic.config.ConfigDict.defer_build] is set.

    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.
    Ú__dataclass_self__r$   Úargsr   Úkwargsr+   r>   c                 _  s"   d}| }|j jt||ƒ|d� d S )NT)Zself_instance)r*   Zvalidate_pythonr   )rE   rF   rG   Z__tracebackhide__Úsr.   r.   r1   Ú__init__v   s   z$complete_dataclass.<locals>.__init__z	.__init__)r:   r<   FZ__post_init_post_parse__zVSupport for `__post_init_post_parse__` has been dropped, the method will not be called)r<   r?   Ú__signature__T)Úinitr@   Úvalidate_by_aliasÚextraÚis_dataclassNú`)Útitleztype[PydanticDataclass]Ú	dataclass)rE   r$   rF   r   rG   r   r+   r>   )$rI   r5   Zconfig_dictr%   rA   Zdefer_buildr   ÚhasattrÚwarningsÚwarnr   r   r   r!   r   r    r(   rL   rM   rJ   Zgenerate_schemar   ÚnameÚcore_configr3   Zclean_schemar   r   r'   r   r4   Zplugin_settingsr*   r   r)   r&   )r0   r:   rB   r<   rC   Zoriginal_initrI   r?   Z
gen_schemaZschemaÚerV   r.   r.   r1   Úcomplete_dataclassU   sn   


þý	øþ"€üþ
ÿrX   úTypeIs[type[StandardDataclass]]c                C  s   d| j v o
t| dƒ S )af  Returns `True` if the class is a stdlib dataclass and *not* a Pydantic dataclass.

    Unlike the stdlib `dataclasses.is_dataclass()` function, this does *not* include subclasses
    of a dataclass that are themselves not dataclasses.

    Args:
        cls: The class.

    Returns:
        `True` if the class is a stdlib dataclass, `False` otherwise.
    Ú__dataclass_fields__r*   )Ú__dict__rR   r/   r.   r.   r1   Úis_stdlib_dataclassÁ   s   r\   Úpydantic_fieldr   údataclasses.Field[Any]c                 C  sp   d| i}t jdkr| jd ur| j|d< | jd ur| j|d< | jdur'| j|d< | jdu r0d|d< tjd	i |¤ŽS )
NÚdefault)é   é   ÚdocÚkw_onlyTÚreprFrK   r.   )ÚsysÚversion_infoÚdescriptionrc   rd   rK   ÚdataclassesÚfield)r]   Z
field_argsr.   r.   r1   Úas_dataclass_fieldÐ   s   





rj   r
   ÚDcFieldsúGenerator[None]c                 c  s  � g }| j dd… D ]M}|j di ¡}dd„ | ¡ D ƒ}|rW| ||f¡ | ¡ D ]-\}}tt|jƒ}t |¡}|j	durA|j	|_	|j
durJ|j
|_
|jdu rRd|_|||< q)q
zdV  W |D ]\}	}
|
 ¡ D ]\}}||	|< qgq_dS |D ]\}	}
|
 ¡ D ]\}}||	|< q}quw )a°  Temporarily patch the stdlib dataclasses bases of `cls` if the Pydantic `Field()` function is used.

    When creating a Pydantic dataclass, it is possible to inherit from stdlib dataclasses, where
    the Pydantic `Field()` function is used. To create this Pydantic dataclass, we first apply
    the stdlib `@dataclass` decorator on it. During the construction of the stdlib dataclass,
    the `kw_only`, `repr` and `init` field arguments need to be understood by the stdlib *during* the
    dataclass construction. To do so, we temporarily patch the fields dictionary of the affected
    bases.

    For instance, with the following example:

    ```python {test="skip" lint="skip"}
    import dataclasses as stdlib_dc

    import pydantic
    import pydantic.dataclasses as pydantic_dc

    @stdlib_dc.dataclass
    class A:
        a: int = pydantic.Field(repr=False)

    # Notice that the `repr` attribute of the dataclass field is `True`:
    A.__dataclass_fields__['a']
    #> dataclass.Field(default=FieldInfo(repr=False), repr=True, ...)

    @pydantic_dc.dataclass
    class B(A):
        b: int = pydantic.Field(repr=False)
    ```

    When passing `B` to the stdlib `@dataclass` decorator, it will look for fields in the parent classes
    and reuse them directly. When this context manager is active, `A` will be temporarily patched to be
    equivalent to:

    ```python {test="skip" lint="skip"}
    @stdlib_dc.dataclass
    class A:
        a: int = stdlib_dc.field(default=Field(repr=False), repr=False)
    ```

    !!! note
        This is only applied to the bases of `cls`, and not `cls` itself. The reason is that the Pydantic
        dataclass decorator "owns" `cls` (in the previous example, `B`). As such, we instead modify the fields
        directly (in the previous example, we simply do `setattr(B, 'b', as_dataclass_field(pydantic_field))`).

    !!! note
        This approach is far from ideal, and can probably be the source of unwanted side effects/race conditions.
        The previous implemented approach was mutating the `__annotations__` dict of `cls`, which is no longer a
        safe operation in Python 3.14+, and resulted in unexpected behavior with field ordering anyway.
    r   NrZ   c                 S  sR   i | ]%\}}t |jtƒr'|jjd us$|jjd us$|jjdus$|jjdu r||“qS )NTF)Ú
isinstancer_   r   rg   rc   rd   rK   )Ú.0Ú
field_nameri   r.   r.   r1   Ú
<dictcomp>%  s    
ýøz%patch_base_fields.<locals>.<dictcomp>TF)Ú__mro__r[   ÚgetÚitemsÚappendr   r   r_   Úcopyrc   rd   rK   )r0   Zoriginal_fields_listÚbaseZ	dc_fieldsZ&dc_fields_with_pydantic_field_defaultsro   ri   r_   Znew_dc_fieldr@   Zoriginal_fieldsZoriginal_fieldr.   r.   r1   Úpatch_base_fieldsê   s>   €7þ




€
ÿÿ
ÿÿrw   r-   )r0   r9   r:   r;   r<   r=   r+   r>   )r0   rD   r:   r;   rB   r,   r<   r=   rC   r,   r+   r,   )r0   rD   r+   rY   )r]   r   r+   r^   )r0   rD   r+   rl   )Fr6   Ú
__future__r   Z_annotationsru   rh   re   rS   Úcollections.abcr   Ú
contextlibr   Ú	functoolsr   Útypingr   r   r   r	   r
   r   Zpydantic_corer   r   r   r   Ztyping_extensionsr   Úerrorsr   r@   r   Zplugin._schema_validatorr   r   r   Ú r   r   Ú_fieldsr   Z_generate_schemar   r   Z	_genericsr   Z_mock_val_serr   Z_namespace_utilsr   Ú
_signaturer    Z_utilsr!   Z	_typeshedr"   ZStandardDataclassÚconfigr#   r$   rA   rX   r\   rj   ÚdictÚstrÚFieldrk   r7   rw   r.   r.   r.   r1   Ú<module>   sN     ýú
l
