o
    Ú­jJ  ã                   @  sl  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
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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	rxddl(m)Z) 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œ
dMd(d)„ƒƒZ0eej/e%e'fd�edddddddddddœ
dNd-d)„ƒƒZ0n4eej/e%e'fd�eddddddddd.œdOd/d)„ƒƒZ0eej/e%e'fd�eddddddddd.œdPd0d)„ƒƒZ0eej/e%e'fd�	dQdddddddddddœ
dRd3d)„ƒZ0dSd5d6„Z1ee2ƒZ3ej.d7k �r$dTd<d=„Z4e4ej5_6ddd>dd?œdUdFdG„Z7dVdKdL„Z8dS )Wz7Provide an enhanced dataclass that performs validation.é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚCallableÚGenericÚLiteralÚNoReturnÚTypeVarÚoverload)Úwarn)Ú	TypeGuardÚdataclass_transformé   )Ú_configÚ_decoratorsÚ_mock_val_serÚ_namespace_utilsÚ_typing_extra)Ú_dataclasses)Úgetattr_migration)Ú
ConfigDict)ÚPydanticUserError)ÚFieldÚ	FieldInfoÚPrivateAttr)ÚPydanticDataclass)ÚMappingNamespace)Ú	dataclassÚrebuild_dataclassÚ_T©é   é
   )Úfield_specifiersFT.©
ÚinitÚreprÚeqÚorderÚunsafe_hashÚfrozenÚconfigÚvalidate_on_initÚkw_onlyÚslotsr%   úLiteral[False]r&   Úboolr'   r(   r)   r*   r+   ú ConfigDict | type[object] | Noner,   úbool | Noner-   r.   Úreturnú-Callable[[type[_T]], type[PydanticDataclass]]c        
   
      C  ó   d S ©N© r$   r7   r7   úQ/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pydantic/dataclasses.pyr      ó   r   Ú_clsútype[_T]útype[PydanticDataclass]c       
         C  r5   r6   r7   )r:   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r7   r7   r8   r   0   r9   ©r%   r&   r'   r(   r)   r*   r+   r,   c                 C  r5   r6   r7   r=   r7   r7   r8   r   C   ó   c          	      C  r5   r6   r7   )	r:   r%   r&   r'   r(   r)   r*   r+   r,   r7   r7   r8   r   R   r>   útype[_T] | NoneúGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c       
      	     sj   |du sJ dƒ‚|dusJ dƒ‚t jdkr|	ˆdœ‰ni ‰d‡ ‡‡‡‡‡‡‡fd
d„}| du r1|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.   Úclsú	type[Any]r3   r<   c              
     sŒ  ddl m} || ƒrtd| j› d�dd�‚| }tdd„ | jD ƒƒ}|s8ˆd	ur8t| d
ƒr8td| j› d�tdd� ˆd	ur>ˆnt	| d
d	ƒ}t
 |¡}tjj| dd�}| |¡ | j}t | ¡ryd	}| f}t| tƒrrt| j }	||	f }t | j|¡} ˆd	ur�ˆ‰ |jrŽtd| j›d�tdd� n|jp“d‰ t | ¡}
|
D ]}t	| |d	ƒ}t|tƒr±t| |t |¡ƒ q›t | ¡� t j!| fdˆˆˆˆ	ˆ dœˆ¤Ž} W d	  ƒ n1 sÒw   Y  |j"�r| j#‰t$ %| j#¡d*‡ ‡fdd„ƒ}| &d	| ¡| _#ˆ�rt| dƒ�sd+d"d#„}d,d%d&„}|| _'|| _(d| _)|| _*|| _t	|d'd	ƒ}|j+| _+t,j-d(k�r0|d	u�r0||_.|| _.|j/| _/t0t1ƒ| _2d| _3tj4| |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)Úcodec                 s  s   � | ]}t  |¡V  qd S r6   )ÚdataclassesÚis_dataclass)Ú.0Úbaser7   r7   r8   Ú	<genexpr>®   s   € 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Ú
stacklevelT)Úreplace_wrapped_methodszN`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.F)r%   r&   r'   r(   r)   r*   Úinstancer   ÚnameÚstrÚvaluer   r3   ÚNonec                  sp   ˆ rˆ| ||ƒS t | ƒ}t||d ƒ}t|tƒr| | |¡ d S t|tjƒr.| j ||¡ d S |j	 
| ||¡ d S r6   )ÚtypeÚgetattrÚ
isinstanceÚpropertyÚ__set__Ú	functoolsÚcached_propertyÚ__dict__Ú__setitem__Ú__pydantic_validator__Úvalidate_assignment)rO   rP   rR   Úinst_clsÚattr©Úfrozen_Úoriginal_setattrr7   r8   Úvalidated_setattrþ   s   
z>dataclass.<locals>.create_dataclass.<locals>.validated_setattrÚ__setstate__Úselfú	list[Any]c                   s   ‡ fdd„t  ˆ ¡D ƒS )Nc                   s   g | ]}t ˆ |jƒ‘qS r7   )rU   rP   )rG   Úf©rf   r7   r8   Ú
<listcomp>  s    zTdataclass.<locals>.create_dataclass.<locals>._dataclass_getstate.<locals>.<listcomp>)rE   Úfieldsri   r7   ri   r8   Ú_dataclass_getstate  s   z@dataclass.<locals>.create_dataclass.<locals>._dataclass_getstateÚstatec                 S  s.   t t | ¡|ƒD ]\}}t | |j|¡ qd S r6   )ÚziprE   rk   ÚobjectÚ__setattr__rP   )rf   rm   ÚfieldrR   r7   r7   r8   Ú_dataclass_setstate  s   ÿz@dataclass.<locals>.create_dataclass.<locals>._dataclass_setstateÚ__firstlineno__)r!   é   )Úraise_errors)rO   r   rP   rQ   rR   r   r3   rS   )rf   r   r3   rg   )rf   r   rm   rg   r3   rS   )5Ú_internal._utilsrC   r   Ú__name__ÚanyÚ	__bases__Úhasattrr   ÚUserWarningrU   r   ÚConfigWrapperr   ÚDecoratorInfosÚbuildÚupdate_from_configÚ__doc__Ú_pydantic_dataclassesÚis_stdlib_dataclassÚ
issubclassr   Ú__parameters__ÚtypesÚ	new_classr*   r   Úsafe_get_annotationsrV   r   ÚsetattrÚas_dataclass_fieldÚpatch_base_fieldsrE   r   r^   rp   rY   ÚwrapsÚ__get__Ú__getstate__re   Ú__is_pydantic_dataclass__Ú__pydantic_decorators__Ú
__module__ÚsysÚversion_infors   Ú__qualname__ÚclassmethodÚ_pydantic_fields_completeÚ__pydantic_fields_complete__Ú__pydantic_complete__Úcomplete_dataclass)rA   rC   Úoriginal_clsÚhas_dataclass_baseÚconfig_dictÚconfig_wrapperÚ
decoratorsÚoriginal_docÚbasesÚgeneric_baseÚcls_annsÚ
field_nameÚfield_valuerd   rl   rr   Úfirstlineno©r+   r'   r*   Úkwargsr(   r&   r.   r)   ra   r8   Úcreate_dataclass™   sž   	þü





ü€


€ÿø	÷ÿ



z#dataclass.<locals>.create_dataclassN)rA   rB   r3   r<   )r‘   r’   )r:   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r§   r7   r¥   r8   r   b   s   /
 !rA   c                 C  s   t dd„ | j ¡ D ƒƒS )z®Return whether the fields were successfully collected (i.e. type hints were successfully resolved).

    This is a private helper, not meant to be used outside Pydantic.
    c                 s  s   � | ]}|j V  qd S r6   )Ú	_complete)rG   Ú
field_infor7   r7   r8   rI   A  s   € z,_pydantic_fields_complete.<locals>.<genexpr>)ÚallÚ__pydantic_fields__Úvalues)rA   r7   r7   r8   r•   <  s   r•   )r!   é   Úargsr   r¦   r   c                  O  s   t dƒ‚)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 callable)Ú	TypeError)r®   r¦   r7   r7   r8   Ú_call_initvarJ  s   r°   rK   )Úforceru   Ú_parent_namespace_depthÚ_types_namespacer±   ru   r²   Úintr³   úMappingNamespace | Nonec                C  sž   |s| j rdS dD ]}|| jv rtt| |ƒtjƒst| |ƒ q	d| _ |dur)|}n|dkr7tj|dd�p5i }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)Ú__pydantic_core_schema__r]   Ú__pydantic_serializer__Fr   T)Úparent_depthr±   )Úparent_namespace)Úcheck)ru   Úns_resolverÚ_force_build)r—   r[   rV   rU   r   Ú
MockValSerÚdelattrr   Úparent_frame_namespacer   Ú
NsResolverr�   r˜   r   r|   rJ   )rA   r±   ru   r²   r³   r`   Ú
rebuild_nsr»   r7   r7   r8   r   T  s,   

€ÿ÷r   Úclass_rB   ú"TypeGuard[type[PydanticDataclass]]c                C  s,   zd| j v o
t | ¡W S  ty   Y dS w )z©Whether a class is a pydantic dataclass.

    Args:
        class_: The class.

    Returns:
        `True` if the class is a pydantic dataclass, `False` otherwise.
    rŽ   F)r[   rE   rF   ÚAttributeError)rÂ   r7   r7   r8   Úis_pydantic_dataclass‘  s
   	ÿrÅ   )r%   r/   r&   r0   r'   r0   r(   r0   r)   r0   r*   r0   r+   r1   r,   r2   r-   r0   r.   r0   r3   r4   )r:   r;   r%   r/   r&   r0   r'   r0   r(   r0   r)   r0   r*   r2   r+   r1   r,   r2   r-   r0   r.   r0   r3   r<   )r%   r/   r&   r0   r'   r0   r(   r0   r)   r0   r*   r2   r+   r1   r,   r2   r3   r4   )r:   r;   r%   r/   r&   r0   r'   r0   r(   r0   r)   r0   r*   r2   r+   r1   r,   r2   r3   r<   r6   )r:   r?   r%   r/   r&   r0   r'   r0   r(   r0   r)   r0   r*   r2   r+   r1   r,   r2   r-   r0   r.   r0   r3   r@   )rA   r<   r3   r0   )r®   r   r¦   r   r3   r   )rA   r<   r±   r0   ru   r0   r²   r´   r³   rµ   r3   r2   )rÂ   rB   r3   rÃ   )9r€   Ú
__future__r   Ú_annotationsrE   rY   r‘   r…   Útypingr   r   r   r   r   r   r	   r
   Úwarningsr   Útyping_extensionsr   r   Ú	_internalr   r   r   r   r   r   r�   Ú
_migrationr   r+   r   Úerrorsr   rk   r   r   r   Ú_internal._dataclassesr   Ú_internal._namespace_utilsr   Ú__all__r   r’   rq   r   r•   rw   Ú__getattr__r°   ÚInitVarÚ__call__r   rÅ   r7   r7   r7   r8   Ú<module>   s¾    (
õô÷öÿô 
Z
ú=