
    h>hQ                    $   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,      Z2 ed-      Z3 ed.d/      Z4 ed0d1      Z5 ed2      Z6 ed3d/      Z7ejp                  r e9e
jN                  e'g      Z:n	 e9e'g      Z:ejv                  rd d4l<m=Z= n e>d      Z= ed5      Z?eee   e@eee0d6f   ZA G d7 d8e*      ZB G d9 d:e*e2         ZC G d; d<e*e3e7f         ZDe'd=   ZEdd>dd?	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dld@ZF	 	 	 	 dmdAZG	 	 	 	 	 	 dndBZHdddC	 	 	 	 	 	 	 	 	 dodDZIddE	 	 	 	 	 	 	 dpdFZJdqdGZKdrdHZLdsdIZMdtdJZNdudKZOdvdLZPdwdMZQdxdNZRdydOZS	 	 dz	 	 	 	 	 	 	 d{dPZTed|dQ       ZUed}dR       ZUe	 	 	 	 dmdS       ZU	 	 	 	 dmdTZUe	 	 	 	 	 	 d~dU       ZVe	 	 	 	 	 	 ddV       ZV	 	 	 	 	 	 ddWZVddXZWdtdYZXddZZY	 	 	 	 	 	 dd[ZZdd\	 	 	 	 	 	 	 dd]Z[dd^Z\ G d_ d`e*      Z] edae],      Z^ G db dcee^         Z_ edde]de      Z` G df dgee`         Za edheedief      ,      Zb G dj dkeeb         Zcy)    )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_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__     Z/var/www/html/DP/alpha_backend/venv/lib/python3.12/site-packages/sqlalchemy/util/typing.pyr7   r7   Z   s     .-rA   r7   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

    r8   r9   Type[_T]
__origin__Nr:   r@   rA   rB   rD   rD   d   s     .-rA   rD   c                      e Zd ZddZddZy)SupportsKeysAndGetItemc                     y Nr@   )selfs    rB   keyszSupportsKeysAndGetItem.keysy   s    SrA   c                     y rJ   r@   )rK   _SupportsKeysAndGetItem__ks     rB   __getitem__z"SupportsKeysAndGetItem.__getitem__{   s    srA   N)returnzIterable[_KT])rN   r-   rP   r3   )r;   r<   r=   rL   rO   r@   rA   rB   rH   rH   x   s    (2rA   rH   *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)rR   N)de_stringify_annotation).0elemrU   clsrT   rX   originating_modulerS   s     rB   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s<      
 , $"- /+  ,s   )
is_fwd_ref__forward_arg__
isinstancestreval_expression
is_generic
is_literalsetaddtupler9   _copy_generic_annotation_with)	r^   
annotationr_   rX   rS   rT   rU   original_annotationelementss	   ` `````  rB   r[   r[      s    . %*//
*c"'
4FGJ$*Gc


 	z":& EM&
 '&j) 
 
 #++
 
 -ZBBrA   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))rf   r   dictrh   listcollections_abc
MutableSetMutableMappingMutableSequencer   Sequencerematchrepr__class_getitem__rj   r   rc   rd   r	   )type_r]   s     rB   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~   rF   )rl   rn   s     rB   rk   rk      s2     z;'##H-- $$X..rA   rW   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	NameErrorrp   
setdefaultr;   updateeval	Exception)	
expressionmodule_namerX   rY   base_globalskecls_namespacerl   errs	            rB   re   re      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rX   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 )re   r   r   r   r   r   builtins)namer   rX   r   r   s        rB   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      rB   resolve_name_to_real_class_namer   C  s:    .T;/ sJ--  s    ))c                0    | d uxr t        |       t        u S rJ   )r   r   r{   s    rB   	is_pep593r   L  s    ?E!2i!??rA   c                h    t        | t        j                        xr t        | t        t        f       S rJ   )rc   rr   r   rd   bytes)r   s    rB   is_non_string_iterabler   P  s1    c?334 Zc5\> : rA   c                $    t        |       t        v S rJ   )r   LITERAL_TYPESr   s    rB   rg   rg   V  s    e--rA   c                    t        | d      S )N__supertype__r   r   s    rB   
is_newtyper   Z  s    5/**rA   c                6    t        | d      xr t        | d      S )Nr9   rF   r   r   s    rB   rf   rf   b  s    5*%F'%*FFrA   c                "    t        | t              S rJ   )rc   r)   r   s    rB   	is_pep695r   f  s    e]++rA   c                d    | j                   }t        |      r|j                   }t        |      r|S rJ   )r   r   )r{   
super_types     rB   flatten_newtyper   j  s0    $$J
Z
 --
 Z
 rA   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 rJ   )ri   r   	__value__is_unionr9   )r{   valuet_seenrecursive_values      rB   r   z&pep695_values.<locals>.recursive_valuez  s`    E> L		%LL,1NN;Nq"N;;;s   AN)	rh   rc   rq   r   popleftextendri   r4   NoneFwd)r{   restypesstackr   r   r   s        @@rB   pep695_valuesr   q  s     EE< %
 C#tc
A!T"Q		!'':":$B  urA   c                    rt        | t              ryt        | t              ry|r)t        |       rt	        fd| j
                  D              S y)NTc              3  :   K   | ]  }t        |d         yw)T)check_for_plain_stringN)ra   )r\   argr   s     rB   r`   zis_fwd_ref.<locals>.<genexpr>  s/      
 & T2H  &s   F)rc   rd   r	   rf   anyr9   )r{   check_genericr   s     `rB   ra   ra     sP    
 *UC"8	E:	&	:e, 
 ~~	
 
 	
 rA   c                     y rJ   r@   r   s    rB   de_optionalize_union_typesr     s    36rA   c                     y rJ   r@   r   s    rB   r   r     s    ?BrA   c                     y rJ   r@   r   s    rB   r   r          rA   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)ra   #_de_optionalize_fwd_ref_union_typesr   includes_noner   py39rh   r9   r   r   appendri   discardr4   r   make_union_type)r{   typstack_of_unionsu_typr]   s        rB   r   r     s     %25%@@	%]51;;enn%C $UGnO%C!'//1!NND~'..t4	 + " KKHG$$ rA   c                     y rJ   r@   r{   return_has_nones     rB   r   r     s     rA   c                     y rJ   r@   r   s     rB   r   r     r   rA   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*r5   Fz\s*\|\s*|c              3  ,   K   | ]  }|d k7  s	|  yw)r5   Nr@   )r\   ps     rB   r`   z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s     B{!a6kA{s   
)rb   rw   rx   groupsplitr	   r   joinstripclearlenr   r*   )r{   r   rl   mmg1rn   currentignore_commacharr]   partspipe_tokenshas_noneanno_strs                 rB   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   rO   )r   s    rB   r   r   #  s    U##rA   c                j   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 )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rJ   r   r\   r   s     rB   r`   z includes_none.<locals>.<genexpr>7  s     =_=#_   r   c              3  2   K   | ]  }t        |        y wrJ   r   r   s     rB   r`   z includes_none.<locals>.<genexpr>;  s     B-A=#-Ar   N)ra   r   r   r   r   r   r   r   r   r   r   r   r4   r   s    rB   r   r   (  s     %25$??=Xe_===Xe_Q/00B]5-ABBB%U0011Wh---rA   c                    t        | dd      S )Nr   	UnionType)is_origin_ofr   s    rB   r   r   A  s    w44rA   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   rc   type
issubclass)r{   	class_objorigins      rB   is_origin_of_clsr   E  s/     F~fd#E
69(EErA   )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       rB   r   r   R  sJ     F~&!U* $>&++66v>rA   c                v    t         j                  r| j                  S t        | dd       }|t        | dd       }|S )Nr;   _name)r   py310r;   r   )r{   typ_names     rB   r   r   a  s:    ||~~5*d3ugt4HrA   c                  $    e Zd ZddZddZddZy)DescriptorProtoc                     y rJ   r@   rK   instanceowners      rB   __get__zDescriptorProto.__get__m  s    CrA   c                     y rJ   r@   rK   r  r   s      rB   __set__zDescriptorProto.__set__o  s    #rA   c                     y rJ   r@   rK   r  s     rB   
__delete__zDescriptorProto.__delete__q  s    rA   N)r  objectr  r   rP   r   )r  r   r   r   rP   r5   r  r   rP   r5   )r;   r<   r=   r  r  r  r@   rA   rB   r  r  l  s    ?=4rA   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 rJ   r@   r
  s      rB   r  zDescriptorReference.__get__      #rA   c                     y rJ   r@   r  s      rB   r  zDescriptorReference.__set__      rA   c                     y rJ   r@   r  s     rB   r  zDescriptorReference.__delete__      SrA   N)r  r  r  r   rP   r  )r  r   r   r  rP   r5   r  r;   r<   r=   r>   r   r  r  r  r@   rA   rB   r  r  w  s     EC8 rA   r  _DESC_co)r,   r/   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 rJ   r@   r
  s      rB   r  zRODescriptorReference.__get__  s    SrA   c                     y rJ   r@   r  s      rB   r  zRODescriptorReference.__set__  r  rA   c                     y rJ   r@   r  s     rB   r  z RODescriptorReference.__delete__  s    rA   N)r  r  r  r   rP   r   )r  r   r   r   rP   r   )r  r   rP   r   r  r@   rA   rB   r"  r"    s     HE< rA   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 rJ   r@   r
  s      rB   r  zCallableReference.__get__  r  rA   c                     y rJ   r@   r  s      rB   r  zCallableReference.__set__  s    crA   c                     y rJ   r@   r  s     rB   r  zCallableReference.__delete__  r  rA   N)r  r  r  r   rP   r&  )r  r   r   r&  rP   r5   r  r  r@   rA   rB   r(  r(    s     CA8 rA   r(  )r^   	Type[Any]rl   _AnnotationScanTyper_   rd   rX   zMapping[str, Any]rS   z#Optional[Callable[[str, str], str]]rT   boolrU   zOptional[Set[Any]]rP   r,  )r{   r-  rP   r-  )rl   zGenericProtocol[_T]rn   r8   rP   rE   )
r   rd   r   rd   rX   Optional[Mapping[str, Any]]rY   zOptional[Type[Any]]rP   r   )r   rd   r   rd   rX   r/  rP   r   )r   rd   r   rd   rP   rd   )r{   zOptional[Any]rP   r.  )r   r   rP   zTypeGuard[Iterable[Any]])r{   r   rP   r.  )r{   zOptional[_AnnotationScanType]rP   zTypeGuard[NewType])r{   r-  rP   zTypeGuard[GenericProtocol[Any]])r{   r-  rP   zTypeGuard[TypeAliasType])r{   r   rP   r,  )r{   r-  rP   zSet[Any])FF)r{   r-  r   r.  r   r.  rP   zTypeGuard[ForwardRef])r{   rd   rP   rd   )r{   r,  rP   r,  )r{   r	   r   zLiteral[True]rP   r.  )r{   r	   r   zLiteral[False]rP   r-  )r{   r	   r   r.  rP   z Union[_AnnotationScanType, bool])r   r-  rP   r,  )r{   r   rP   zTypeGuard[ArgsTypeProtocol])r{   r   r   z'Union[Tuple[Type[Any], ...], Type[Any]]rP   r.  )r{   r   r  rd   r   zOptional[str]rP   r.  )r{   r,  rP   rd   )d
__future__r   r   collectionsr   collections.abcabcrr   rw   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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   py38	frozensetr   r  r   r4   r   r   rd   r-  r7   rD   rH   _LiteralStarr[   r|   rk   re   r   r   r   r   rg   r   rf   r   r   r   ra   r   r   r   r   r   r   r   r   r  r  r  r   r"  r&  r(  r@   rA   rB   <module>r9     s   #   ) 	 
                     8< 106:4<86@888.@0Ten	T	*\6
en	T	*	;; v~~w78Mwi(M 
<< +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.@.+G,"N  #( ! 	( 
 6 
 6 
 B 
 B 
 

&&&R 
(5	 

 
(6 

33(,3%3l$
.25
F
FB
F	
F 6:%2	5h 5 	/9'%. 9( :_E=GH- =" e8HS#X$6789 9rA   