o
    >Diu'                     @   s  d dl Z d dlZd dlZd dlmZ zd dlmZ W n ey)   d dlmZ Y nw z
d dlmZm	Z	 W n! eyU   z
d dlmZm	Z	 W n eyR   d Z	ZY nw Y nw dd Zz	ej
ddd	 W n eyp   d
d ZY nw dd Zejdkrdd Znejdk rdd ZnejZdd Zdd Zdd Zi eeeeeeeeeeejeejeejeejeejeejeejeejeejeej eej!eej"ee j#jee j#jee j#jee j#j!ee j#jee j#jee j#j eiZ$dd Z%dd Z&dd Z'dd Z(dS )     N)_AnnotatedAlias)get_type_hints)NotRequiredRequiredc                 C   s   t | ddS )NT)include_extras)_get_type_hints)obj r	   G/var/www/Datamplify/venv/lib/python3.10/site-packages/msgspec/_utils.pyr      s   r   FooT)is_classc                 C   s   t j| ddS )NF)is_argumenttyping
ForwardRefvaluer	   r	   r
   _forward_ref"   s   r   c                 C   s   t j| dddS )NFT)r   r   r   r   r	   r	   r
   r   '      )      c                 C   s   t | ||dS )Nr	   )r   
_eval_type)tglobalnslocalnsr	   r	   r
   r   .   r   r   )r   
   c                 C   sz   zt | ||W S  ty< } z(zddlm} W n ty)   td| jd|w || ||ddW  Y d }~S d }~ww )Nr   )eval_type_backportz#Unable to evaluate type annotation a  . If you are making use of the new typing syntax (unions using `|` since Python 3.10 or builtins subscripting since Python 3.9), you should either replace the use of new syntax with the existing `typing` constructs or install the `eval_type_backport` package.F)try_default)r   r   	TypeErrorr   ImportError__forward_arg__)r   r   r   er   r	   r	   r
   r   2   s(   c                    sd   t | tjr | | S zt| j}W n ty   |  Y S w |s#| S t fdd|D }| | S )Nc                 3   s    | ]	}  ||V  qd S N)get).0pmappingr	   r
   	<genexpr>Y   s    z _apply_params.<locals>.<genexpr>)
isinstancer   TypeVarr#   tuple__parameters__	Exception)r   r'   
parametersargsr	   r&   r
   _apply_paramsJ   s   r0   c                    s<   i t | tr
| }n| j} fdd  | i  |jfS )Nc                    s   t | tr
| }i }n8t| dd }|d ttjfv s|v rd S |j}t fdd| jD }t	|t	|ks7J t
t|| |< }t|tjrYt|d|j}|D ]	}|| qQd S d S )N
__origin__c                 3   s    | ]}t | V  qd S r"   )r0   )r$   ascoper	   r
   r(   n   s    zE_get_class_mro_and_typevar_mappings.<locals>.inner.<locals>.<genexpr>__orig_bases__)r)   typegetattrobjectr   Genericr,   r+   __args__lendictzip
issubclass	__bases__)cr4   cls	new_scopeparamsr/   basesbinnerr'   r3   r
   rG   e   s    
z2_get_class_mro_and_typevar_mappings.<locals>.inner)r)   r6   r1   __mro__)r   rA   r	   rF   r
   #_get_class_mro_and_typevar_mappings]   s   


rI   c                 C   s   i }t | \}}|D ][}|tjtfv rq
||}tt|}ttj	|j
ddi }|jdi }| D ].\}	}
|	|v r?q6|
du rHtd}
n	t|
trQt|
}
t|
||}
|dur`t|
|}
|
||	< q6q
|S )a  Get the annotations for a class.

    This is similar to ``typing.get_type_hints``, except:

    - We maintain it
    - It leaves extras like ``Annotated``/``ClassVar`` alone
    - It resolves any parametrized generics in the class mro. The returned
      mapping may still include ``TypeVar`` values, but those should be treated
      as their unparametrized variants (i.e. equal to ``Any`` for the common case).

    Note that this function doesn't check that Generic types are being used
    properly - invalid uses of `Generic` may slip through without complaint.

    The assumption here is that the user is making use of a static analysis
    tool like ``mypy``/``pyright`` already, which would catch misuse of these
    APIs.
    N__dict____annotations__)rI   r   r9   r8   r#   r<   varsr7   sysmodules
__module__rJ   itemsr6   r)   strr   r   r0   )r   hintsmrotypevar_mappingsrA   r'   
cls_localscls_globalsannnamer   r	   r	   r
   get_class_annotations{   s,   




rY   c                 C   s   t | tr| }n| j}t| }t|drt|j}n|jr"t|}nt }i }| D ]0\}}t	|dd}|t
u rF|| |jd ||< q+|tu rW|| |jd ||< q+|||< q+||fS )N__required_keys__r1   Fr   )r)   r6   r1   rY   hasattrsetrZ   	__total__rP   r7   r   addr:   r   discard)r   rA   	raw_hintsrequiredrR   kvoriginr	   r	   r
   get_typeddict_info   s(   





re   c                 C   s  t | tr| }n| j}t| }g }g }g }t|drddlm}m}m} |j	
 D ]H}	|	j|ur:|	j|u r9tdq)|	j}
||
 }|	j|urU||	j ||
|df q)|	j|uri||	j ||
|df q)||
|df q)|| d }t|dd }nqddlm}m} g }|jD ]K}	|	j}
||
 }|	j}||urt ||r|jrtd	||j ||
|df n|| ||
|df n||
|df |	jd ur||	 q|| t|d
d }t|dd }|rt||}|t|t|||fS )N__dataclass_fields__r   )_FIELD_FIELD_INITVARMISSINGz3dataclasses with `InitVar` fields are not supportedFT__post_init__)NOTHINGFactoryzvSupport for default factories with `takes_self=True` is not implemented. File a GitHub issue if you need this feature!__attrs_pre_init____attrs_post_init__)r)   r6   r1   rY   r[   dataclassesrg   rh   ri   rf   values_field_typer   rX   defaultappenddefault_factoryextendr7   attrsrk   rl   __attrs_attrs__
takes_selfNotImplementedErrorfactory	validator_wrap_attrs_validatorsr+   )r   rA   rR   ra   optionaldefaultsrg   rh   ri   fieldrX   typpre_init	post_initrk   rl   fields_with_validatorsrr   r	   r	   r
   get_dataclass_info   sl   













r   c                    s    fdd}|S )Nc                    s8    D ]}| | |t| |j qd ur|  d S d S r"   )r{   r7   rX   )r   r   fieldsr   r	   r
   rG   4  s
   z%_wrap_attrs_validators.<locals>.innerr	   )r   r   rG   r	   r   r
   r|   3  s   r|   c                 C   s   | di |S )z1Used to unpickle Structs with keyword-only fieldsNr	   r	   )rA   kwargsr	   r	   r
   rebuild=  s   r   ))collectionsrM   r   r   typing_extensionsr   r   r-   r   r   r   r   r   version_infor   r0   rI   rY   listr+   r\   	frozensetr<   ListTupleSet	FrozenSetDict
CollectionMutableSequenceSequenceMutableMappingMapping
MutableSetAbstractSetabc_CONCRETE_TYPESre   r   r|   r   r	   r	   r	   r
   <module>   s   



/	
#J
