B
    hnd*                 @  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	m
Z
mZmZ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 dd	lmZ dd
lmZ ddlmZ erddlmZ dZ edZ!ej"dkrheej#efde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$eej#efde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$neej#efdeddddddddd!dddddddddd"	d#dZ$eej#efdeddddddddd!ddddddddddd$
d%dZ$eej#efdd7d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$ee%Z&d)ej"  krfd*k rn nd+d+d,d-d.d/Z'e'ej(_)ddd0dd1dddd2d3dd4d5d6Z*dS )8z7Provide an enhanced dataclass that performs validation.    )annotationsN)TYPE_CHECKINGAnyCallableGenericNoReturnTypeVaroverload)Literaldataclass_transform   )_config_decorators_typing_extra)_dataclasses)getattr_migration)
ConfigDict)Field)PydanticDataclass)	dataclassrebuild_dataclass_T)   
   )Zfield_specifiersFT.)
initrepreqorderunsafe_hashfrozenconfigvalidate_on_initkw_onlyslotszLiteral[False]boolz ConfigDict | type[object] | Nonezbool | Nonez-Callable[[type[_T]], type[PydanticDataclass]])r   r   r   r   r   r   r    r!   r"   r#   returnc    
   
      C  s   d S )N )
r   r   r   r   r   r   r    r!   r"   r#   r&   r&   8/tmp/pip-unpacked-wheel-y3jxpnai/pydantic/dataclasses.pyr      s    r   ztype[_T]ztype[PydanticDataclass])_clsr   r   r   r   r   r   r    r!   r"   r#   r%   c   
         C  s   d S )Nr&   )r(   r   r   r   r   r   r   r    r!   r"   r#   r&   r&   r'   r   +   s    )r   r   r   r   r   r   r    r!   )	r   r   r   r   r   r   r    r!   r%   c             C  s   d S )Nr&   )r   r   r   r   r   r   r    r!   r&   r&   r'   r   ?   s    )
r(   r   r   r   r   r   r   r    r!   r%   c      	      C  s   d S )Nr&   )	r(   r   r   r   r   r   r   r    r!   r&   r&   r'   r   N   s    ztype[_T] | NonezGCallable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]c   
      	     sr   dkst d|dk	s t dtjdkr8t|	|
dni ddd fd	d
}| dkrj|S || S )a  A decorator used to create a Pydantic-enhanced dataclass, similar to the standard Python `dataclasses`,
    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 or not to include the field in the __repr__ output.
        eq: Determines if a `__eq__` 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 an unsafe hashing function should be included in the class.
        frozen: Determines if the generated class should be a 'frozen' dataclass, which does not allow its
            attributes to be modified from its constructor.
        config: A configuration for the dataclass generation.
        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 supported)r   r   )r"   r#   z	type[Any]ztype[PydanticDataclass])clsr%   c       
   	     s   | } }|dkr(t | dd}|dk	r(|}t|}tj| }| j}t| rd}| f}t	| t
rvt
| j }||f }t| j|} tj| fd} || _|| _|j| _|j| _tj| |ddd}	|	| _| S )zCreate a Pydantic dataclass from a regular dataclass.

        Args:
            cls: The class to create the Pydantic dataclass from.

        Returns:
            A Pydantic dataclass.
        N__pydantic_config__)r   r   r   r   r   r   F)raise_errorstypes_namespace)getattrr   ConfigWrapperr   ZDecoratorInfosbuild__doc___pydantic_dataclassesZis_builtin_dataclass
issubclassr   __parameters__types	new_class__name__dataclassesr   Z__pydantic_decorators__
__module____qualname__complete_dataclass__pydantic_complete__)
r)   Zoriginal_clsZconfig_dictZ
cls_configZconfig_wrapperZ
decoratorsZoriginal_docbasesZgeneric_baseZpydantic_complete)r    r   r   r   kwargsr   r   r   r&   r'   create_dataclass   sB    	




z#dataclass.<locals>.create_dataclassN)AssertionErrorsysversion_infodict)r(   r   r   r   r   r   r   r    r!   r"   r#   r>   r&   )r    r   r   r   r=   r   r   r   r'   r   _   s    ,
"<)r      )r      r   r   )argsr=   r%   c              O  s   t ddS )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 callableN)	TypeError)rE   r=   r&   r&   r'   _call_initvar   s    rG      )forcer+   _parent_namespace_depth_types_namespaceintzdict[str, Any] | None)r)   rI   r+   rJ   rK   r%   c            C  sp   |s| j rdS |dk	r | }n.|dkr>tj|dp6i }|}ni }t| |}tj| tj| j	dd||dS dS )a}  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 build the dataclass core schema for.
        force: Whether to force the rebuilding of the model 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`.
    Nr   )Zparent_depthF)check)r+   r,   )
r;   copyr   Zparent_frame_namespaceZget_cls_types_namespacer1   r:   r   r.   r*   )r)   rI   r+   rJ   rK   r,   Zframe_parent_nsr&   r&   r'   r      s    

r   )N)+r0   
__future__r   Z_annotationsr7   r@   r4   typingr   r   r   r   r   r   r	   typing_extensionsr
   r   	_internalr   r   r   r   r1   Z
_migrationr   r    r   fieldsr   Z_internal._dataclassesr   __all__r   rA   fieldr   r6   __getattr__rG   ZInitVar__call__r   r&   r&   r&   r'   <module>   s   $,0(*,i