o
    ;hu'                     @   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	   A/var/www/html/venv/lib/python3.10/site-packages/msgspec/_utils.pyr      s   r   Z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)Z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   r.   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    )r.   )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__)cr2   clsZ	new_scopeparamsr-   basesbinnerr%   r1   r
   rD   e   s    
z2_get_class_mro_and_typevar_mappings.<locals>.inner)r'   r4   r/   __mro__)r   r?   r	   rC   r
   #_get_class_mro_and_typevar_mappings]   s   


rF   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__)rF   r   r7   r6   r!   r:   varsr5   sysmodules
__module__rG   itemsr4   r'   strr   r   r.   )r   hintsmroZtypevar_mappingsr?   r%   Z
cls_localsZcls_globalsannnamer   r	   r	   r
   get_class_annotations{   s,   




rS   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__r/   Fr   )r'   r4   r/   rS   hasattrsetrT   	__total__rM   r5   r   addr8   r   discard)r   r?   Z	raw_hintsrequiredrO   kvoriginr	   r	   r
   get_typeddict_info   s(   





r^   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!Z__attrs_pre_init__Z__attrs_post_init__)r'   r4   r/   rS   rU   dataclassesr`   ra   rb   r_   values_field_typer   rR   defaultappenddefault_factoryextendr5   attrsrd   re   Z__attrs_attrs__Z
takes_selfNotImplementedErrorfactory	validator_wrap_attrs_validatorsr)   )r   r?   rO   rZ   optionaldefaultsr`   ra   rb   fieldrR   typZpre_init	post_initrd   re   Zfields_with_validatorsri   r	   r	   r
   get_dataclass_info   sl   













rw   c                    s    fdd}|S )Nc                    s8    D ]}| | |t| |j qd ur|  d S d S r    )rp   r5   rR   )r   rt   fieldsrv   r	   r
   rD   4  s
   z%_wrap_attrs_validators.<locals>.innerr	   )ry   rv   rD   r	   rx   r
   rq   3  s   rq   c                 C   s   | di |S )z1Used to unpickle Structs with keyword-only fieldsNr	   r	   )r?   kwargsr	   r	   r
   rebuild=  s   r{   ))collectionsrJ   r   r   typing_extensionsr   r   r+   r   r   r   r   r   version_infor   r.   rF   rS   listr)   rV   	frozensetr:   ListTupleSet	FrozenSetDict
CollectionMutableSequenceSequenceMutableMappingMapping
MutableSetAbstractSetabcZ_CONCRETE_TYPESr^   rw   rq   r{   r	   r	   r	   r
   <module>   s   



/	
#J
