U
    ¶ÜŸjW  ã                   @  sö   d Z ddlmZ ddlZddl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mZ ejrÂdd
lmZ ddlmZmZmZ ddlmZ ddlmZ edeefd�G dd„ dejƒƒZnejZdZe d¡Z G dd„ deej!e  ed�Z"dS )z%RootModel class and type definitions.é    )ÚannotationsN)ÚcopyÚdeepcopy)ÚPydanticUndefinedé   )ÚPydanticUserError)Ú_model_constructionÚ_repr)Ú	BaseModelÚ_object_setattr)ÚAny)ÚLiteralÚSelfÚdataclass_transform)ÚField)ÚPrivateAttrF)Úkw_only_defaultÚfield_specifiersc                   @  s   e Zd ZdS )Ú_RootModelMetaclassN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú7/tmp/pip-unpacked-wheel-3sxb4rlg/pydantic/root_model.pyr      s   r   )Ú	RootModelÚRootModelRootTypec                      s  e Zd ZU dZdZdZdZded< ‡ fdd„Ze	fddd	œd
d„Z
de
_ed/ddddœ‡ fdd„ƒZddœdd„Zdddœdd„Zddœdd„Zd0dddœdd„Zejræ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'd(„Zd"d$d)œ‡ fd*d+„Zd,dœd-d.„Z‡  ZS )1r   a‘  Usage docs: https://docs.pydantic.dev/2.10/concepts/models/#rootmodel-and-custom-root-types

    A Pydantic `BaseModel` for the root object of the model.

    Attributes:
        root: The root object of the model.
        __pydantic_root_model__: Whether the model is a RootModel.
        __pydantic_private__: Private fields in the model.
        __pydantic_extra__: Extra fields in the model.

    TNr   Úrootc                   s2   | j  d¡}|d k	r tddd�‚tƒ jf |Ž d S )NÚextraz<`RootModel` does not support setting `model_config['extra']`zroot-model-extra)Úcode)Zmodel_configÚgetr   ÚsuperÚ__init_subclass__)ÚclsÚkwargsr   ©Ú	__class__r   r   r!   6   s     ÿzRootModel.__init_subclass__ÚNone)r   Úreturnc                K  s0   d}|r|t k	rtdƒ‚|}| jj|| d� d S )NTz_"RootModel.__init__" accepts either a single positional argument or arbitrary keyword arguments)Zself_instance)r   Ú
ValueErrorZ__pydantic_validator__Zvalidate_python)Úselfr   ÚdataZ__tracebackhide__r   r   r   Ú__init__>   s    ÿzRootModel.__init__zset[str] | Noner   )r   Ú_fields_setr'   c                   s   t ƒ j||d�S )aS  Create a new model using the provided root object and update fields set.

        Args:
            root: The root object of the model.
            _fields_set: The set of fields to be updated.

        Returns:
            The new model.

        Raises:
            NotImplemented: If the model is not a subclass of `RootModel`.
        )r   r,   )r    Úmodel_construct)r"   r   r,   r$   r   r   r-   J   s    zRootModel.model_constructzdict[Any, Any])r'   c                 C  s   | j | jdœS )N©Ú__dict__Ú__pydantic_fields_set__r.   ©r)   r   r   r   Ú__getstate__Z   s    þzRootModel.__getstate__)Ústater'   c                 C  s$   t | d|d ƒ t | d|d ƒ d S )Nr0   r/   )r   )r)   r3   r   r   r   Ú__setstate__`   s    zRootModel.__setstate__c                 C  s:   t | ƒ}| |¡}t|dt| jƒƒ t|dt| jƒƒ |S )z$Returns a shallow copy of the model.r/   r0   )ÚtypeÚ__new__r   r   r/   r0   )r)   r"   Úmr   r   r   Ú__copy__d   s
    
zRootModel.__copy__zdict[int, Any] | None)Úmemor'   c                 C  s>   t | ƒ}| |¡}t|dt| j|d�ƒ t|dt| jƒƒ |S )z!Returns a deep copy of the model.r/   )r9   r0   )r5   r6   r   r   r/   r   r0   )r)   r9   r"   r7   r   r   r   Ú__deepcopy__l   s
    
zRootModel.__deepcopy__ÚpythonF)ÚmodeÚincludeÚexcludeÚcontextÚby_aliasÚexclude_unsetÚexclude_defaultsÚexclude_noneÚ
round_tripÚwarningsÚserialize_as_anyz!Literal[('json', 'python')] | strr   zdict[str, Any] | NoneÚboolz)bool | Literal[('none', 'warn', 'error')])r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r'   c                C  s   dS )a  This method is included just to get a more accurate return type for type checkers.
            It is included in this `if TYPE_CHECKING:` block since no override is actually necessary.

            See the documentation of `BaseModel.model_dump` for more details about the arguments.

            Generally, this method will have a return type of `RootModelRootType`, assuming that `RootModelRootType` is
            not a `BaseModel` subclass. If `RootModelRootType` is a `BaseModel` subclass, then the return
            type will likely be `dict[str, Any]`, as `model_dump` calls are recursive. The return type could
            even be something different, in the case of a custom serializer.
            Thus, `Any` is used here to catch all of these cases.
            Nr   )r)   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   r   r   r   Ú
model_dumpx   s    zRootModel.model_dump)Úotherr'   c                   s2   t |tƒstS | jd j|jd jko0tƒ  |¡S ©Nr   )Ú
isinstancer   ÚNotImplementedZ__pydantic_fields__Ú
annotationr    Ú__eq__)r)   rI   r$   r   r   rN   ”   s    
ÿ
þzRootModel.__eq__z_repr.ReprArgsc                 c  s   d| j fV  d S rJ   )r   r1   r   r   r   Ú__repr_args__›   s    zRootModel.__repr_args__)N)N)r   r   r   Ú__doc__Z__pydantic_root_model__Z__pydantic_private__Z__pydantic_extra__Ú__annotations__r!   r   r+   Z__pydantic_base_init__Úclassmethodr-   r2   r4   r8   r:   ÚtypingÚTYPE_CHECKINGrH   rN   rO   Ú__classcell__r   r   r$   r   r   #   s:   


ó(r   )Ú	metaclass)#rP   Ú
__future__r   Z_annotationsrS   r   r   Zpydantic_corer   Ú r   Ú	_internalr   r	   Úmainr
   r   rT   r   Útyping_extensionsr   r   r   Úfieldsr   ZPydanticModelFieldr   ZPydanticModelPrivateAttrZModelMetaclassr   Ú__all__ÚTypeVarr   ÚGenericr   r   r   r   r   Ú<module>   s$   
