o
    7ήc4                     @   s   d dl Z d dl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 er2d dlmZ e jdk rCd	ed
 defddZn	dedefddZd	ed
 deded fddZded deded fddZdS )    N)TYPE_CHECKINGAnyDict	FrozenSet
NamedTupleType   Required)	BaseModelcreate_model)is_typeddictis_typeddict_special)	TypedDict)      typeddict_clsr   returnc                 C   s   t | o
t| jdkS )Ntyping)r   type
__module__)r    r   ?/tmp/pip-target-vg8gfxp4/lib/python/pydantic/annotated_types.pyis_legacy_typeddict   s   r   _c                 C   s   dS )NFr   )r   r   r   r   r      s   kwargsr   c                    sn   t | ds	tdt| rtdd | j D rtd| j  fdd| j D }t| j	fi ||S )z
    Create a `BaseModel` based on the fields of a `TypedDict`.
    Since `typing.TypedDict` in Python 3.8 does not store runtime information about optional keys,
    we raise an error if this happens (see https://bugs.python.org/issue38834).
    __required_keys__zYou should use `typing_extensions.TypedDict` instead of `typing.TypedDict` with Python < 3.9.2. Without it, there is no way to differentiate required and optional fields when subclassed.c                 s   s    | ]}t |V  qd S N)r   ).0tr   r   r   	<genexpr>)   s    
z.create_model_from_typeddict.<locals>.<genexpr>zYou should use `typing_extensions.TypedDict` instead of `typing.TypedDict` with Python < 3.11. Without it, there is no way to reflect Required/NotRequired keys.c                    s&   i | ]\}}||| v rt nd fqS r   r	   r   
field_name
field_typerequired_keysr   r   
<dictcomp>2   s    z/create_model_from_typeddict.<locals>.<dictcomp>)
hasattr	TypeErrorr   any__annotations__valuesr   itemsr   __name__)r   r   field_definitionsr   r$   r   create_model_from_typeddict   s   

r/   namedtuple_clsr   c                 K   sD   t | ddpdd | jD }dd | D }t| jfi ||S )z
    Create a `BaseModel` based on the fields of a named tuple.
    A named tuple can be created with `typing.NamedTuple` and declared annotations
    but also with `collections.namedtuple`, in this case we consider all fields
    to have type `Any`.
    r*   Nc                 S   s   i | ]}|t qS r   )r   )r   kr   r   r   r&   B   s    z0create_model_from_namedtuple.<locals>.<dictcomp>c                 S   s   i | ]	\}}||t fqS r   r	   r!   r   r   r   r&   E   s    )getattr_fieldsr,   r   r-   )r0   r   namedtuple_annotationsr.   r   r   r   create_model_from_namedtuple:   s   r5   )sysr   r   r   r   r   r   r   fieldsr
   mainr   r   r   r   typing_extensionsr   version_infoboolr   r/   r5   r   r   r   r   <module>   s$     

"$