a
    [gQ                  
   @  s  d dl mZ d dlZd dlmZ d dlmZ d dlZd dl	Z	d dl
Z
d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d d	l
mZ d d
l
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ ddlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d d lm(Z( d d!lm)Z) d d"lm*Z* d d#lm+Z+ d d$lm,Z, d d%lm-Z- d d&lm.Z. d d'lm/Z/ d d(lm0Z0 d d)lm1Z1 ed*ed+Z2ed,Z3ed-d.d/Z4ed0d.d1Z5ed2Z6ed3d.d/Z7ej8rXe9e
j'e'gZ:n
e9e'gZ:ej;rxd d4l<m=Z= ne>dZ=ed5Z?eee e@eee0d6f ZAG d7d8 d8e*ZBG d9d: d:e*e2 ZCG d;d< d<e*e3e7f ZDe'd= ZEdd>dd?d@dAdBdCdDdEdFd@dGdHdIZFdAdAdJdKdLZGdMdNdOdPdQdRZHdddSdBdBdTdUdVdWdXdYZIddZdBdBdTdVd[d\d]ZJdBdBdBd^d_d`ZKdadEdJdbdcZLdVdddedfdgZMdVdEdJdhdiZNdjdkdJdldmZOdAdndJdodpZPdAdqdJdrdsZQdtd@dJdudvZRdAdwdJdxdyZSddAdEdEdzd{d|d}ZTedBdBdJd~dZUed@d@dJddZUedAdAdJddZUdAdAdJddZUedddEdddZVedddAdddZVddEddddZVdAd@dddZWdVdEdJddZXdVddJddZYdVddEdddZZdddVdBddEdddZ[d@dBdJddZ\G dd de*Z]ede]d+Z^G dd dee^ Z_ede]d.dZ`G dd dee` Zaedeedef  d+ZbG dd deeb ZcdS )    )annotationsN)deque)Any)Callable)cast)Dict
ForwardRef)Generic)Iterable)Mapping)NewType)NoReturn)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )compat)	Annotated)Concatenate)dataclass_transform)Final)final)get_args)
get_origin)Literal)NotRequired)	ParamSpec)Protocol)SupportsIndex)	TypeAlias)	TypedDict)	TypeGuard)Self)TypeAliasType)Never_T)bound_KT_KT_coT)	covariant
_KT_contra)contravariant_VT_VT_co)NoneTypeNonezGenericProtocol[Any]c                   @  s   e Zd ZU dZded< dS )ArgsTypeProtocolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    Tuple[_AnnotationScanType, ...]__args__N__name__
__module____qualname____doc____annotations__ r?   r?   d/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/util/typing.pyr6   Z   s   
r6   c                   @  s"   e Zd ZU dZded< ded< dS )GenericProtocolzXprotocol for generic types.

    this since Python.typing _GenericAlias is private

    r7   r8   Type[_T]
__origin__Nr9   r?   r?   r?   r@   rA   d   s   
rA   c                   @  s*   e Zd ZddddZddddd	Zd
S )SupportsKeysAndGetItemzIterable[_KT])returnc                 C  s   d S Nr?   )selfr?   r?   r@   keysy       zSupportsKeysAndGetItem.keysr-   r3   )_SupportsKeysAndGetItem__krE   c                 C  s   d S rF   r?   )rG   rJ   r?   r?   r@   __getitem__{   rI   z"SupportsKeysAndGetItem.__getitem__N)r:   r;   r<   rH   rK   r?   r?   r?   r@   rD   x   s   rD   *Fstr_cleanup_fninclude_generic_already_seenz	Type[Any]_AnnotationScanTypestrzMapping[str, Any]z#Optional[Callable[[str, str], str]]boolzOptional[Set[Any]])cls
annotationoriginating_modulelocals_rN   rO   rP   rE   c          	        s   |}t |r|j}t|tr:r*|}t|d}rt|rt|s du r\t  | v rh|S  | t	 fdd|j
D }t||S |S )a;  Resolve annotations that may be string based into real objects.

    This is particularly important if a module defines "from __future__ import
    annotations", as everything inside of __annotations__ is a string. We want
    to at least have generic containers like ``Mapped``, ``Union``, ``List``,
    etc.

    rW   in_classNc              
   3  s$   | ]}t | d V  qdS )rM   N)de_stringify_annotation.0elemrP   rT   rO   rW   rV   rN   r?   r@   	<genexpr>   s   
z*de_stringify_annotation.<locals>.<genexpr>)
is_fwd_ref__forward_arg__
isinstancerR   eval_expression
is_generic
is_literalsetaddtupler8   _copy_generic_annotation_with)	rT   rU   rV   rW   rN   rO   rP   Zoriginal_annotationelementsr?   r^   r@   rZ      s2    




rZ   )type_rE   c              	   C  sb   t | r^t| ttttjtjtjtj	tj
fv r^tdt| s^t| tdd t| D S | S )zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')]
    and similar for list, set

    z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set)c                 S  s"   g | ]}t |trt|n|qS r?   )rb   rR   r	   r[   r?   r?   r@   
<listcomp>   s   z,fixup_container_fwd_refs.<locals>.<listcomp>)rd   r   dictrf   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rh   r   rk   r?   r?   r@   fixup_container_fwd_refs   s4    	ry   zGenericProtocol[_T]r7   rB   )rU   rj   rE   c                 C  s"   t | dr| |S | j| S d S )N	copy_with)hasattrrz   rC   )rU   rj   r?   r?   r@   ri      s    

ri   rX   zOptional[Mapping[str, Any]]zOptional[Type[Any]]r   )
expressionmodule_namerW   rY   rE   c          	   
   C  s   zt j| j}W n: tyJ } z"td| d|  |W Y d }~n
d }~0 0 zH|d urt|j}||j| || t	| ||}nt	| ||}W n4 t
y } ztd| |W Y d }~nd }~0 0 |S d S )NModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )sysmodules__dict__KeyError	NameErrorrm   
setdefaultr:   updateeval	Exception)	r|   r}   rW   rY   base_globalskeZcls_namespacerU   errr?   r?   r@   rc      s0    

rc   rW   )namer}   rW   rE   c                C  s   d| v rt | ||dS ztj| j}W n: ty` } z"td| d|  |W Y d }~n
d }~0 0 z
||  W S  ty } zNztj|  W W  Y d }~S  ty   Y n0 td|  d| |W Y d }~n
d }~0 0 d S )N.r   r~   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rc   r   r   r   r   r   builtins)r   r}   rW   r   r   r?   r?   r@   eval_name_only!  s0    
r   )r   r}   rE   c                 C  s6   zt | |}W n ty$   |  Y S 0 t|d| S d S )Nr:   )r   r   getattr)r   r}   objr?   r?   r@   resolve_name_to_real_class_nameC  s
    
r   zOptional[Any]c                 C  s   | d uot | tu S rF   )r   r   rx   r?   r?   r@   	is_pep593L  s    r   zTypeGuard[Iterable[Any]])r   rE   c                 C  s   t | tjot | ttf S rF   )rb   ro   r   rR   bytes)r   r?   r?   r@   is_non_string_iterableP  s    r   c                 C  s   t | tv S rF   )r   LITERAL_TYPESrx   r?   r?   r@   re   V  s    re   zOptional[_AnnotationScanType]zTypeGuard[NewType]c                 C  s
   t | dS )N__supertype__r{   rx   r?   r?   r@   
is_newtypeZ  s    r   zTypeGuard[GenericProtocol[Any]]c                 C  s   t | dot | dS )Nr8   rC   r   rx   r?   r?   r@   rd   b  s    rd   zTypeGuard[TypeAliasType]c                 C  s
   t | tS rF   )rb   r)   rx   r?   r?   r@   	is_pep695f  s    r   r   c                 C  s   | j }t|r|j }q|S rF   )r   r   )rk   Z
super_typer?   r?   r@   flatten_newtypej  s    r   zSet[Any]c                   s   t    fdd| }t|trvt  }t|}|rr| }t|trV|| q4||tthv rjdn| q4|S |hS dS )zExtracts the value from a TypeAliasType, recursively exploring unions
    and inner TypeAliasType to flatten them into a single set.

    Forward references are not evaluated, so no recursive exploration happens
    into them.
    c                   sH   |  v r| S   |  t| s"| S | j}t|s4|S fdd|jD S )Nc                   s   g | ]} |qS r?   r?   r\   t)recursive_valuer?   r@   rl     rI   z:pep695_values.<locals>.recursive_value.<locals>.<listcomp>)rg   r   Z	__value__is_unionr8   )rk   value_seenr   r?   r@   r   z  s    
z&pep695_values.<locals>.recursive_valueN)	rf   rb   rn   r   popleftextendrg   r4   NoneFwd)rk   restypesstackr   r?   r   r@   pep695_valuesq  s    

r   zTypeGuard[ForwardRef])rk   check_genericcheck_for_plain_stringrE   c                   sL    rt | trdS t | tr dS |rDt| rDt fdd| jD S dS d S )NTc                 3  s   | ]}t |d  dV  qdS )Tr   N)r`   )r\   argr   r?   r@   r_     s   zis_fwd_ref.<locals>.<genexpr>F)rb   rR   r	   rd   anyr8   )rk   r   r   r?   r   r@   r`     s    
r`   c                 C  s   d S rF   r?   rx   r?   r?   r@   de_optionalize_union_types  s    r   c                 C  s   d S rF   r?   rx   r?   r?   r@   r     s    c                 C  s   d S rF   r?   rx   r?   r?   r@   r     s    c                 C  s   t | rt| dS t| rt| rtjr4t| j}nRt| g}t }|r||	 }|jD ]"}t|rn|
| qV|| qVqD|d |t |t t| S | S dS )zGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    Contains extra logic to work on non-flattened unions, unions that contain
    ``None`` (seen in py38, 37)

    FN)r`   #_de_optionalize_fwd_ref_union_typesr   includes_noner   Zpy39rf   r8   r   r   appendrg   discardr4   r   make_union_type)rk   typZstack_of_unionsZu_typr]   r?   r?   r@   r     s$    





r	   zLiteral[True])rk   return_has_nonerE   c                 C  s   d S rF   r?   rk   r   r?   r?   r@   r     s    r   zLiteral[False]c                 C  s   d S rF   r?   r   r?   r?   r@   r     s    z Union[_AnnotationScanType, bool]c                 C  s  | j }td|}|r4|ddd }|dkrJ|r<dS t|dS |dkr&d	|dv rg }g }d
}|dD ]`}|d	kr|d7 }n@|dkr|d8 }n.|d
kr|dkr|d|  |	  qx|| qxntd|d}dd |D }	|rt
|t
|	kS |	r t|	 S tS n|r0dS | S td|}
d|
v }|rR|S |r~ddd |
D }|rzt|S tS | S )zreturn the non-optional type for Optional[], Union[None, ...], x|None,
    etc. without de-stringifying forward refs.

    unfortunately this seems to require lots of hardcoded heuristics

    z^(.+?)\[(.+)\]$r   r   r   T   r   [r   ], z,\s*c                 S  s   g | ]}|d krt |qS )r5   r   r[   r?   r?   r@   rl     rI   z7_de_optionalize_fwd_ref_union_types.<locals>.<listcomp>Fz\s*\|\s*r5   |c                 s  s   | ]}|d kr|V  qdS )r5   Nr?   )r\   pr?   r?   r@   r_     rI   z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)ra   rt   ru   groupsplitr	   r   joinstripclearlenr   r*   )rk   r   rU   mmg1rj   currentZignore_commacharpartsZpipe_tokensZhas_noneZanno_strr?   r?   r@   r     sF    



)r   rE   c                  G  s
   t | S )zMake a Union type.)r   rK   )r   r?   r?   r@   r   #  s    r   c                 C  s   t | rt| dS t| r0tdd t| D S t| rHtt| d S t| rftdd t| D S t	| rxt| j
S | ttdfv S )a.  Returns if the type annotation ``type_`` allows ``None``.

    This function supports:
    * forward refs
    * unions
    * pep593 - Annotated
    * pep695 - TypeAliasType (does not support looking into
    fw reference of other pep695)
    * NewType
    * plain types like ``int``, ``None``, etc
    Tc                 s  s   | ]}t |V  qd S rF   r   r   r?   r?   r@   r_   7  rI   z includes_none.<locals>.<genexpr>r   c                 s  s   | ]}t |V  qd S rF   r   r   r?   r?   r@   r_   ;  rI   N)r`   r   r   r   r   r   r   r   r   r   r   r   r4   rx   r?   r?   r@   r   (  s    

r   zTypeGuard[ArgsTypeProtocol]c                 C  s   t | ddS )Nr   Z	UnionType)is_origin_ofrx   r?   r?   r@   r   A  s    r   z'Union[Tuple[Type[Any], ...], Type[Any]])rk   	class_objrE   c                 C  s(   t | }|du rdS t|to&t||S )z[return True if the given type has an __origin__ that shares a base
    with the given classNF)r   rb   type
issubclass)rk   r   originr?   r?   r@   is_origin_of_clsE  s    r   )modulezOptional[str])rk   namesr   rE   c                G  s4   t | }|du rdS t||v o2|du p2|j|S )z\return True if the given type has an __origin__ with the given name
    and optional module.NF)r   _get_type_namer;   
startswith)rk   r   r   r   r?   r?   r@   r   R  s    r   c                 C  s4   t jr| jS t| dd }|d u r,t| dd }|S d S )Nr:   _name)r   py310r:   r   )rk   Ztyp_namer?   r?   r@   r   a  s    r   c                   @  s@   e Zd ZddddddZdddddd	Zddd
ddZdS )DescriptorProtoobjectr   instanceownerrE   c                 C  s   d S rF   r?   rG   r   r   r?   r?   r@   __get__m  rI   zDescriptorProto.__get__r5   r   r   rE   c                 C  s   d S rF   r?   rG   r   r   r?   r?   r@   __set__o  rI   zDescriptorProto.__set__r   rE   c                 C  s   d S rF   r?   rG   r   r?   r?   r@   
__delete__q  rI   zDescriptorProto.__delete__N)r:   r;   r<   r   r   r   r?   r?   r?   r@   r   l  s   r   _DESCc                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZdS )DescriptorReferencea  a descriptor that refers to a descriptor.

    used for cases where we need to have an instance variable referring to an
    object that is itself a descriptor, which typically confuses typing tools
    as they don't know when they should use ``__get__`` or not when referring
    to the descriptor assignment as an instance variable. See
    sqlalchemy.orm.interfaces.PropComparator.prop

    r   r   r   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zDescriptorReference.__get__r5   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zDescriptorReference.__set__r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zDescriptorReference.__delete__Nr:   r;   r<   r=   r   r   r   r   r?   r?   r?   r@   r   w  s
   
r   _DESC_co)r,   r/   c                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZdS )RODescriptorReferenceza descriptor that refers to a descriptor.

    same as :class:`.DescriptorReference` but is read-only, so that subclasses
    can define a subtype as the generically contained element

    r   r   r   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zRODescriptorReference.__get__r   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zRODescriptorReference.__set__r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   z RODescriptorReference.__delete__Nr   r?   r?   r?   r@   r     s
   r   _FN.c                   @  sH   e Zd ZdZerDddddddZdddd	d
dZdddddZdS )CallableReferenceza descriptor that refers to a callable.

    works around mypy's limitation of not allowing callables assigned
    as instance variables


    r   r   r   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zCallableReference.__get__r5   r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zCallableReference.__set__r   c                 C  s   d S rF   r?   r   r?   r?   r@   r     rI   zCallableReference.__delete__Nr   r?   r?   r?   r@   r     s
   r   )FF)d
__future__r   r   collectionsr   collections.abcabcro   rt   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ztyping_extensionsr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r-   r.   r0   r2   r3   Zpy38	frozensetr   r   r   r4   r   r   rR   rQ   r6   rA   rD   Z_LiteralStarrZ   ry   ri   rc   r   r   r   r   re   r   rd   r   r   r   r`   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r?   r?   r?   r@   <module>	   s   

	 G)("	'  )6