
    hMZ                    L   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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 d d+lm2Z2  ed,e-      Z3 ed.      Z4 ed/d0      Z5 ed1d2      Z6 ed3      Z7 ed4d0      Z8ejr                  rd d5l:m;Z; n e<d      Z; ed6      Z=eee   e>eee0d7f   Z? G d8 d9e*      Z@ G d: d;e*e3         ZA G d< d=e*e4e8f         ZBe'd>   ZCdd?dd@	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dpdAZD	 	 	 	 dqdBZE	 	 	 	 	 	 drdCZFdddD	 	 	 	 	 	 	 	 	 dsdEZGddF	 	 	 	 	 	 	 dtdGZHdudHZIdvdIZJdwdJZKdxdKZLdydLZMdzdMZNd{dNZOd|dOZPd}dPZQ	 	 d~	 	 	 	 	 	 	 ddQZReddR       ZSeddS       ZSe	 	 	 	 dqdT       ZS	 	 	 	 dqdUZSe	 	 	 	 	 	 ddV       ZTe	 	 	 	 	 	 ddW       ZT	 	 	 	 	 	 ddXZTddYZUdxdZZVdxd[ZWdd\ZX	 	 	 	 	 	 dd]ZYdd^	 	 	 	 	 	 	 dd_ZZdd`Z[ G da dbe*      Z\ edce\-      Z] G dd deee]         Z^ edfe\dg      Z_ G dh diee_         Z` edjeedkef      -      Za G dl dmeea         Zb G dn do      Zc ec       ZdereZeedjN                  ZfyedZeedjN                  Zfy)    )annotationsN)deque)Any)Callable)cast)Dict)
ForwardRef)Generic)Iterable)Mapping)NewType)NoReturn)Optional)overload)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )compatT)	Annotated)Concatenate)dataclass_transform)Final)final)get_args)
get_origin)Literal)NotRequired)	ParamSpec)Protocol)SupportsIndex)	TypeAlias)	TypedDict)	TypeGuard)Self)TypeAliasType)Never)LiteralString_T)bound_KT_KT_co)	covariant
_KT_contra)contravariant_VT_VT_co)NoneTypeNonezGenericProtocol[Any]c                      e Zd ZU dZded<   y)ArgsTypeProtocolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    Tuple[_AnnotationScanType, ...]__args__N__name__
__module____qualname____doc____annotations__     ?D:\EasyAligner\venv\Lib\site-packages\sqlalchemy/util/typing.pyr8   r8   U   s     .-rB   r8   c                  &    e Zd ZU dZded<   ded<   y)GenericProtocolzXprotocol for generic types.

    this since Python.typing _GenericAlias is private

    r9   r:   Type[_T]
__origin__Nr;   rA   rB   rC   rE   rE   _   s     .-rB   rE   c                      e Zd ZddZddZy)SupportsKeysAndGetItemc                     y NrA   )selfs    rC   keyszSupportsKeysAndGetItem.keyst   s    SrB   c                     y rK   rA   )rL   _SupportsKeysAndGetItem__ks     rC   __getitem__z"SupportsKeysAndGetItem.__getitem__v   s    srB   N)returnzIterable[_KT])rO   r.   rQ   r4   )r<   r=   r>   rM   rP   rA   rB   rC   rI   rI   s   s    (2rB   rI   *Fstr_cleanup_fninclude_generic_already_seenc               l    |}t        |      r|j                  }t        |t              rr	 |      }t	        |       }rht        |      r]t        |      sR
t               |v r|S j                  |       t         f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.

    locals_in_classc           
   3  B   K   | ]  }t        |         yw)rS   N)de_stringify_annotation).0elemrV   clsrU   rY   originating_modulerT   s     rC   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s<      
 , $"- /+  ,s   )
is_fwd_ref__forward_arg__
isinstancestreval_expression
is_generic
is_literalsetaddtupler:   _copy_generic_annotation_with)	r_   
annotationr`   rY   rT   rU   rV   original_annotationelementss	   ` `````  rC   r\   r\   }   s    . %*//
*c"'
4FGJ$*Gc


 	z":& EM&
 '&j) 
 
 #++
 
 -ZBBrB   c                   t        |       rt        |       t        t        t        t
        j                  t
        j                  t
        j                  t
        j                  t
        j                  fv rtt        j                  dt        |             sUt        |       j                  t        t!        |       D cg c]  }t#        |t$              rt'        |      n|! c}            S | S c c}w )zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')]
    and similar for list, set

    z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set))rg   r   dictri   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rk   r   rd   re   r	   )type_r^   s     rC   fixup_container_fwd_refsr}      s     	5u&&**++##$$	


 A4;

 % 22 !) / )34(=Jt$4G /
 	
 Ls   8$C)c                Z    t        | d      r| j                  |      S | j                  |   S )N	copy_with)hasattrr   rG   )rm   ro   s     rC   rl   rl      s2     z;'##H-- $$X..rB   rX   c                  	 t         j                  |   j                  }	 |Qt        |j                        }|j                  |j                  |       |j                  |       t        | ||      }|S t        | ||      }	 |S # t        $ r}t	        d| d|        |d }~ww xY w# t        $ r}t	        d|       |d }~ww xY w)NModule z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )sysmodules__dict__KeyError	NameErrorrq   
setdefaultr<   updateeval	Exception)	
expressionmodule_namerY   rZ   base_globalskecls_namespacerm   errs	            rC   rf   rf      s    '*{{;'?'H'H !2!23M$$X%6%6A
   .j-AJ  j,@J 1  k] ###-,0
 	&  0?
	s5   B AB& 3B& 	B#BB#&	C/B>>CrY   c               J   d| v rt        | ||      S 	 t        j                  |   j                  }	 ||    S # t        $ r}t        d| d|        |d }~ww xY w# t        $ r?}	 t        j                  |    cY d }~S # t        $ r Y nw xY wt        d|  d|       |d }~ww xY w)N.r   r   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rf   r   r   r   r   r   builtins)namer   rY   r   r   s        rC   eval_name_onlyr     s     d{t['BB'*{{;'?'H'HD!!  k] # 6#
 	  		$$T** 		 $TF+k]C
		sJ   7 A 	A AA	B"$A<6B"<	BBBBB"c                X    	 t        | |      }t        |d|       S # t        $ r | cY S w xY w)Nr<   )r   getattrr   )r   r   objs      rC   resolve_name_to_real_class_namer   >  s:    .T;/ sJ--  s    ))c                D    | d uxr t        |       t        j                  v S rK   )r   _type_tuplesr   r|   s    rC   	is_pep593r   G  s"    LE!2l6L6L!LLrB   c                h    t        | t        j                        xr t        | t        t        f       S rK   )rd   rs   r   re   bytes)r   s    rC   is_non_string_iterabler   K  s1    c?334 Zc5\> : rB   c                8    t        |       t        j                  v S rK   )r   r   r    r   s    rC   rh   rh   Q  s    e 4 444rB   c                    t        | d      S )N__supertype__r   r   s    rC   
is_newtyper   U  s    5/**rB   c                6    t        | d      xr t        | d      S )Nr:   rG   r   r   s    rC   rg   rg   ]  s    5*%F'%*FFrB   c                v    t        |       rt        | j                        S t        | t        j
                        S rK   )rg   	is_pep695rG   rd   _type_instancesr)   r   s    rC   r   r   a  s0    
 %))**e_::;;rB   c                d    | j                   }t        |      r|j                   }t        |      r|S rK   )r   r   )r|   
super_types     rC   flatten_newtyper   k  s0    $$J
Z
 --
 Z
 rB   c                :   t               fd |       }t        |t              rot               }t        |      }|rV|j	                         }t        |t              r|j                  |       n!|j                  |t        t        hv rdn|       |rV|S |h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                    | v r| S j                  |        t        |       s| S | j                  }t        |      s|S |j                  D cg c]
  } |       c}S c c}w rK   )rj   r   	__value__is_unionr:   )
inner_typevaluet_seenrecursive_values      rC   r   z&pep695_values.<locals>.recursive_value{  se     		*$$$L,1NN;Nq"N;;;s   AN)	ri   rd   rr   r   popleftextendrj   r5   NoneFwd)r|   restypesstackr   r   r   s        @@rC   pep695_valuesr   r  s     EE< %
 C#tc
A!T"Q		!'':":$B  urB   c                    rt        | t              ryt        | t        j                        ry|r)t	        |       rt        fd| j                  D              S y)NTc              3  :   K   | ]  }t        |d         yw)T)check_for_plain_stringN)rb   )r]   argr   s     rC   ra   zis_fwd_ref.<locals>.<genexpr>  s/      
 & T2H  &s   F)rd   re   r   r	   rg   anyr:   )r|   check_genericr   s     `rC   rb   rb     sV    
 *UC"8	E?55	6	:e, 
 ~~	
 
 	
 rB   c                     y rK   rA   r   s    rC   de_optionalize_union_typesr     s    36rB   c                     y rK   rA   r   s    rC   r   r     s    ?BrB   c                     y rK   rA   r   s    rC   r   r          rB   c                   t        |       rt        | d      S t        |       rt        |       rt        j
                  rt        | j                        }n{t        | g      }t               }|rR|j                         }|j                  D ]0  }t        |      r|j                  |        |j                  |       2 |rR|j                  d       |j                  t               |j                  t               t        | S | 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)rb   #_de_optionalize_fwd_ref_union_typesr   includes_noner   py39ri   r:   r   r   appendrj   discardr5   r   make_union_type)r|   typstack_of_unionsu_typr^   s        rC   r   r     s     %25%@@	%]51;;enn%C $UGnO%C!'//1!NND~'..t4	 + " KKHG$$ rB   c                     y rK   rA   r|   return_has_nones     rC   r   r     s     rB   c                     y rK   rA   r   s     rC   r   r     r   rB   c                   | j                   }t        j                  d|      }|r^|j                  d      j	                  d      d   }|dk(  r|rdS t        |j                  d            S |dk(  rd	|j                  d      v rg }g }d
}|j                  d      D ]r  }|d	k(  r|dz  }nT|dk(  r|dz  }nI|d
k(  rD|dk(  r?|j                  dj                  |      j                                |j                          b|j                  |       t n%t        j                  d|j                  d            }|D 	cg c]  }	|	dk7  s	t        |	       }
}	|rt        |      t        |
      k7  S |
rt        |
 S t        S |rdS | S t        j                  d|      }d|v }|r|S |r+dj                  d |D              }|rt        |      S t        S | S c c}	w )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*r6   Fz\s*\|\s*|c              3  ,   K   | ]  }|d k7  s	|  yw)r6   NrA   )r]   ps     rC   ra   z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s     B{!a6kA{s   
)rc   rx   ry   groupsplitr	   r   joinstripclearlenr   r*   )r|   r   rm   mmg1ro   currentignore_commacharr^   partspipe_tokenshas_noneanno_strs                 rC   r   r     s    &&J	$j	1B	XXa[s#B'*4G
288A;0GG7]bhhqk!&(%' HHQKDs{$)$)%*ts{ (8(>(>(@A NN4( ( 88GRXXa[92:M($dfnZ%(EM8}E
2227.BUB+566((;
3K$H88B{BB'/z(#:U:L! Ns   ;
GGc                 ,    t        j                  |       S )zMake a Union type.)r   rP   )r   s    rC   r   r   $  s    U##rB   c                   t        |       rt        | d      S t        |       rt        d t	        |       D              S t        |       rt        t	        |       d         S t        |       rt        d t        |       D              S t        |       rt        | j                        S 	 | t        t        dfv S # t        $ r Y yw xY w)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              3  2   K   | ]  }t        |        y wrK   r   r]   r   s     rC   ra   z includes_none.<locals>.<genexpr>8  s     =_=#_   r   c              3  2   K   | ]  }t        |        y wrK   r   r   s     rC   ra   z includes_none.<locals>.<genexpr><  s     B-A=#-Ar   NF)rb   r   r   r   r   r   r   r   r   r   r   r   r5   	TypeErrorr   s    rC   r   r   )  s     %25$??=Xe_===Xe_Q/00B]5-ABBB%U0011(D111  	s   'B6 6	CCc                    t        | t              xsB t        | d      xs4 | j                  dv xs$ t        |       j                  d   j                  dv S )NrG   )typingtyping_extensionsr   )rd   typer   r=   __mro__r   s    rC   	is_a_typer   H  s\    5$ 	P5,'	P>>	P ;q!,,0OO	rB   c                    t        | dd      S )Nr   	UnionType)is_origin_ofr   s    rC   r   r   Q  s    w44rB   c                Z    t        |       }|yt        |t              xr t        ||      S )z[return True if the given type has an __origin__ that shares a base
    with the given classF)r   rd   r   
issubclass)r|   	class_objorigins      rC   is_origin_of_clsr  U  s/     F~fd#E
69(EErB   )modulec               ~    t        |       }|yt        |      |v xr! |du xs |j                  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)r|   r  namesr  s       rC   r  r  b  sJ     F~&!U* $>&++66v>rB   c                v    t         j                  r| j                  S t        | dd       }|t        | dd       }|S )Nr<   _name)r   py310r<   r   )r|   typ_names     rC   r	  r	  q  s:    ||~~5*d3ugt4HrB   c                  $    e Zd ZddZddZddZy)DescriptorProtoc                     y rK   rA   rL   instanceowners      rC   __get__zDescriptorProto.__get__}  s    CrB   c                     y rK   rA   rL   r  r   s      rC   __set__zDescriptorProto.__set__  s    #rB   c                     y rK   rA   rL   r  s     rC   
__delete__zDescriptorProto.__delete__  s    rB   N)r  objectr  r   rQ   r   )r  r   r   r   rQ   r6   r  r   rQ   r6   )r<   r=   r>   r  r  r  rA   rB   rC   r  r  |  s    ?=4rB   r  _DESCc                  .    e Zd ZdZerddZddZddZyy)	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

    c                     y rK   rA   r  s      rC   r  zDescriptorReference.__get__      #rB   c                     y rK   rA   r  s      rC   r  zDescriptorReference.__set__      rB   c                     y rK   rA   r  s     rC   r  zDescriptorReference.__delete__      SrB   N)r  r  r  r   rQ   r  )r  r   r   r  rQ   r6   r  r<   r=   r>   r?   r   r  r  r  rA   rB   rC   r!  r!    s     EC8 rB   r!  _DESC_co)r-   r0   c                  .    e Zd ZdZerddZddZddZyy)	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

    c                     y rK   rA   r  s      rC   r  zRODescriptorReference.__get__  s    SrB   c                     y rK   rA   r  s      rC   r  zRODescriptorReference.__set__  r#  rB   c                     y rK   rA   r  s     rC   r  z RODescriptorReference.__delete__  s    rB   N)r  r  r  r   rQ   r)  )r  r   r   r   rQ   r   )r  r   rQ   r   r(  rA   rB   rC   r+  r+    s     HE< rB   r+  _FN.c                  .    e Zd ZdZerddZddZddZyy)	CallableReferenceza descriptor that refers to a callable.

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


    c                     y rK   rA   r  s      rC   r  zCallableReference.__get__  r%  rB   c                     y rK   rA   r  s      rC   r  zCallableReference.__set__  s    crB   c                     y rK   rA   r  s     rC   r  zCallableReference.__delete__  r'  rB   N)r  r  r  r   rQ   r/  )r  r   r   r/  rQ   r6   r  r(  rA   rB   rC   r1  r1    s     CA8 rB   r1  c                      e Zd ZddZy)_TypingInstancesc                    t        t        t        |d       t        t        |d       fD ch c]  }|| c}      }|st	        |      || j
                  |<   |S c c}w rK   )rk   r   r   r   AttributeErrorr   )rL   keyr   r   s       rC   __getattr__z_TypingInstances.__getattr__  sw     FC.-sD9A = 	
  %%"cs   AN)r9  re   rQ   ztuple[type, ...])r<   r=   r>   r:  rA   rB   rC   r6  r6    s    rB   r6  )r_   	Type[Any]rm   _AnnotationScanTyper`   re   rY   zMapping[str, Any]rT   z#Optional[Callable[[str, str], str]]rU   boolrV   zOptional[Set[Any]]rQ   r;  )r|   r<  rQ   r<  )rm   zGenericProtocol[_T]ro   r9   rQ   rF   )
r   re   r   re   rY   Optional[Mapping[str, Any]]rZ   zOptional[Type[Any]]rQ   r   )r   re   r   re   rY   r>  rQ   r   )r   re   r   re   rQ   re   )r|   zOptional[Any]rQ   r=  )r   r   rQ   zTypeGuard[Iterable[Any]])r|   r   rQ   r=  )r|   zOptional[_AnnotationScanType]rQ   zTypeGuard[NewType])r|   r<  rQ   zTypeGuard[GenericProtocol[Any]])r|   r<  rQ   zTypeGuard[TypeAliasType])r|   r   rQ   r;  )r|   r<  rQ   zSet[Any])FF)r|   r<  r   r=  r   r=  rQ   zTypeGuard[ForwardRef])r|   re   rQ   re   )r|   r;  rQ   r;  )r|   r	   r   zLiteral[True]rQ   r=  )r|   r	   r   zLiteral[False]rQ   r<  )r|   r	   r   r=  rQ   z Union[_AnnotationScanType, bool])r   r<  rQ   r;  )r|   r   rQ   zTypeGuard[ArgsTypeProtocol])r|   r   r  z'Union[Tuple[Type[Any], ...], Type[Any]]rQ   r=  )r|   r   r  re   r  zOptional[str]rQ   r=  )r|   r;  rQ   re   )g
__future__r   r   collectionsr   collections.abcabcrs   rx   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r.   r/   r1   r3   r4   r  r   r5   r   r   re   r<  r8   rE   rI   _LiteralStarr\   r}   rl   rf   r   r   r   r   rh   r   rg   r   r   r   rb   r   r   r   r   r   r   r  r  r	  r  r  r!  r)  r+  r/  r1  r6  r   r   LITERAL_TYPESrA   rB   rC   <module>rE     s   #   ) 	 
                      8< 106:4<86@888.@0@Ten	T	*\6
en	T	*	<< +DzH
V
 IsJ8NN 
.x .hrl (3Xc6k2 3 s| ;?!(,D	D#D D 	D 8D D &D DN&&&R/#//N// ,0$(!!! )	!
 "! 	!P ,0	
 )	
 	D.M5+G<"N  #( ! 	( 
 6 
 6 
 B 
 B 
 

&&&R 
(5	 

 
(6 

33(,3%3l$
>5
F
FB
F	
F 6:%2	5h 5 	/9'%. 9( :_E=GH- =" e8HS#X$6789 9$ $  !'O $$ #O$$rB   