
    e?                       d dl mZ d dl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m.Z.  ed)e	*          Z/ ed+          Z0 ed,d-          Z1 ed.d/          Z2 ed0          Z3 ed1d-          Z4ej5        rd d2l6m7Z7 n e8d          Z7 ed3          Z9e#Z:e$Z;eee	         e<eee.d4f         Z= G d5 d6e(          Z> G d7 d8e(e/                   Z? G d9 d:e(e0e4f                   Z@e%d;         ZAdd<dd=ddMZBddRZCddSddXZDddSddZZEdd[ZFdd\dd]ZGdd`ZHddcZIdddZJddfZKddhZLddjZMddlZN	 dddoZOeddp            ZPeddq            ZPeddr            ZPddsZPdduZQddwZR	 ddd{ZSdd}ZTdd~ZUddZVddZWddddZXddZY G d de(          ZZ edeZ*          Z[ G d dee[                   Z\ edeZd          Z] G d dee]                   Z^ edee
de	f                  *          Z_ G d dee_                   Z`dS )    )annotationsN)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_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<   dS )ArgsTypeProcotolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    Tuple[_AnnotationScanType, ...]__args__N__name__
__module____qualname____doc____annotations__     6lib/python3.11/site-packages/sqlalchemy/util/typing.pyr6   r6   T   s*           .-----r@   r6   c                  (    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@   rA   rC   rC   ^   s6           .---r@   rC   c                      e Zd Zd	dZd
dZdS )SupportsKeysAndGetItemreturnIterable[_KT]c                    d S Nr?   )selfs    rA   keyszSupportsKeysAndGetItem.keyss       r@   _SupportsKeysAndGetItem__kr,   r2   c                    d S rK   r?   )rL   rO   s     rA   __getitem__z"SupportsKeysAndGetItem.__getitem__v   rN   r@   N)rH   rI   )rO   r,   rH   r2   )r:   r;   r<   rM   rQ   r?   r@   rA   rG   rG   r   s<                r@   rG   *Fstr_cleanup_fninclude_generic_already_seencls	Type[Any]
annotation_AnnotationScanTypeoriginating_modulestrlocals_Mapping[str, Any]rT   #Optional[Callable[[str, str], str]]rU   boolrV   Optional[Set[Any]]rH   c                   |}t          |          r|j        }t          |t                    r r |          }t	          |          }r~t          |          rot          |          s`t                      |v r|S                     |           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.

    r]   Nc           
   3  D   K   | ]}t          |           V  dS )rS   Nde_stringify_annotation).0elemrV   rW   rU   r]   r[   rT   s     rA   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s]       
 
  $"- /+  
 
 
 
 
 
r@   )
is_fwd_ref__forward_arg__
isinstancer\   eval_expression
is_generic
is_literalsetaddtupler8   _copy_generic_annotation_with)	rW   rY   r[   r]   rT   rU   rV   original_annotationelementss	   ` `````  rA   rf   rf   ~   sC   . %* 0/
*c"" 
 	H'
4FGGJ$*G
 
 


 	Cz""C :&&C
  EEM&&
 '&j))) 
 
 
 
 
 
 
 
 
 #+
 
 
 
 
 -ZBBBr@   GenericProtocol[_T]ru   r7   rD   c                f    t          | d          r|                     |          S | j        |         S )N	copy_with)hasattrrx   rE   )rY   ru   s     rA   rs   rs      s:     z;'' /##H--- $X..r@   rc   
expressionmodule_nameOptional[Mapping[str, Any]]r   c                   	 t           j        |         j        }n(# t          $ r}t	          d| d|            |d }~ww xY w	 t          | ||          }|S # 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	NameErroreval	Exception)rz   r{   r]   base_globalskerY   errs          rA   rm   rm      s    '*{;'?'H   0k 0 0#-0 0
 
 	*lG<<
     ???
 
	s(    
?:?A 
A8 A33A8namec               b   d| v rt          | ||          S 	 t          j        |         j        }n(# t          $ r}t          d| d|            |d }~ww xY w	 ||          S # t          $ rC}	 t          j        |          cY d }~S # t          $ r Y nw xY wt          d|  d|           |d }~ww xY w)N.rc   r~   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rm   r   r   r   r   r   builtins)r   r{   r]   r   r   s        rA   eval_name_onlyr      s'    d{{t['BBBB'*{;'?'H   #k # # # #
 
 	D!! 	 	 		$T******* 	 	 	D	 CTCCkCC
 
		sJ   0 
AAAA! !
B.,B=B.
BB)BB))B.c                j    	 t          | |          }t          |d|           S # t          $ r | cY S w xY w)Nr:   )r   getattrr   )r   r{   objs      rA   resolve_name_to_real_class_namer   	  sP    .T;// sJ---    s   # 22rT   c               @     t           fd|j        D              S )Nc           	     8    g | ]}t          |i            S )r   re   )rg   annorW   r[   rT   s     rA   
<listcomp>z/de_stringify_union_elements.<locals>.<listcomp>  sI     	

 	

 	

  $"-  	

 	

 	

r@   )make_union_typer8   )rW   rY   r[   r]   rT   s   ` ` `rA   de_stringify_union_elementsr     sI     	

 	

 	

 	

 	

 	

 #+	

 	

 	

 r@   type_Optional[_AnnotationScanType]c                6    | d uot          |           t          u S rK   )typing_get_originr   r   s    rA   	is_pep593r   (  s     F!25!9!9Y!FFr@   r   TypeGuard[Iterable[Any]]c                p    t          | t          j                  ot          | t          t          f           S rK   )rl   collections_abcr   r\   bytes)r   s    rA   is_non_string_iterabler   ,  s6    c?344 Zc5\> > : r@   c                .    t          |           t          u S rK   )r   r    r   s    rA   ro   ro   2  s    e''r@   TypeGuard[NewType]c                "    t          | d          S )N__supertype__ry   r   s    rA   
is_newtyper   6  s    5/***r@   TypeGuard[GenericProtocol[Any]]c                B    t          | d          ot          | d          S )Nr8   rE   r   r   s    rA   rn   rn   >  s!    5*%%F'%*F*FFr@   TypeGuard[TypeAliasType]c                ,    t          | t                    S rK   )rl   r)   r   s    rA   	is_pep695r   B  s    e]+++r@   r   c                ^    | j         }t          |          r|j         }t          |          |S rK   )r   r   )r   
super_types     rA   flatten_newtyper   F  s:    $J
Z
 
  .-
 Z
 
  .r@   check_genericTypeGuard[ForwardRef]c                    t          | t                    rdS |r-t          |           rt          d | j        D                       S dS )NTc              3  6   K   | ]}t          |d           V  dS )TN)rj   )rg   args     rA   ri   zis_fwd_ref.<locals>.<genexpr>S  s,      CCS:c4((CCCCCCr@   F)rl   r	   rn   anyr8   )r   r   s     rA   rj   rj   M  sV     %$$ t	 :e,, CCENCCCCCCur@   c                    d S rK   r?   r   s    rA   de_optionalize_union_typesr   X      Cr@   c                    d S rK   r?   r   s    rA   r   r   ]  r   r@   c                    d S rK   r?   r   s    rA   r   r   b  s	     Cr@   c                   t          |           rt          |           S t          |           rQt          | j                  }|                    t                     |                    t                     t          | S | S )zmGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    )	rj   "de_optionalize_fwd_ref_union_typesis_optionalrp   r8   discardr3   NoneFwdr   )r   typs     rA   r   r   i  sw     % 1%888	U		 	%.!!HG$$ r@   r	   c                   | j         }t          j        d|          }|r|                    d          dk    r"t	          |                    d                    S |                    d          dk    r;t          j        d|                    d                    }t          d |D              S | S t          j        d|          }d	|v r,t	          d
                    d |D                                 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   z,\s*c                8    g | ]}|d k    t          |          S )r4   r   )rg   rh   s     rA   r   z6de_optionalize_fwd_ref_union_types.<locals>.<listcomp>  s%    JJJt46>>*T"">>>r@   z\s*\|\s*r4   |c              3  &   K   | ]}|d k    |V  dS )r4   Nr?   )rg   ps     rA   ri   z5de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s&      "I"IQ&[[1[[[["I"Ir@   )rk   rematchgroupr	   splitr   join)r   rY   mmru   pipe_tokenss        rA   r   r     s     &J	$j	1	1B	 	88A;;*$$bhhqkk***XXa[[G##x!55H"JJxJJJ  L(;
33K#(("I"Ik"I"I"IIIJJJLr@   typesc                 \    t          t          t                                        |           S )zMake a Union type.

    This is needed by :func:`.de_optionalize_union_types` which removes
    ``NoneType`` from a ``Union``.

    )r   r   r   rQ   )r   s    rA   r   r     s"     U''...r@   include_uniondiscard_noneTuple[Type[Any], ...]c                    t          |           rTt          | j                  }|r|                    t                     |r| ft          |          z   S t          |          S | fS )zPReturn a type as a tuple of individual types, expanding for
    ``Union`` types.)is_unionrp   r8   r   r3   rr   )r   r   r   r   s       rA   expand_unionsr     si      %.!! 	"KK!!! 	8eCjj((::xr@   TypeGuard[ArgsTypeProcotol]c                &    t          | ddd          S )Nr   r   	UnionTypeis_origin_ofr   s    rA   r   r     s     	  r@   c                L    t          |           ot          t          |           v S rK   )r   r3   typing_get_argsr   s    rA   is_optional_unionr     s"    uD(oe.D.D"DDr@   c                "    t          | d          S )Nr   r   r   s    rA   r   r     s    w'''r@   	class_obj'Union[Tuple[Type[Any], ...], Type[Any]]c                r    t          |           }|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   rl   type
issubclass)r   r   origins      rA   is_origin_of_clsr     s:     u%%F~ufd##E
69(E(EEr@   )modulenamesr   Optional[str]c                   t          |           }|dS t          |          |v o|du p|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   r   r   s       rA   r   r     sR     u%%F~u&!!U* $>&+66v>>r@   c                t    t           j        r| j        S t          | dd           }|t          | dd           }|S )Nr:   _name)r   py310r:   r   )r   typ_names     rA   r   r     sA    | ~5*d33ugt44Hr@   c                  &    e Zd ZddZdd	Zdd
ZdS )DescriptorProtoinstanceobjectownerr   rH   c                    d S rK   r?   rL   r   r   s      rA   __get__zDescriptorProto.__get__  rN   r@   valuer4   c                    d S rK   r?   rL   r   r   s      rA   __set__zDescriptorProto.__set__  rN   r@   c                    d S rK   r?   rL   r   s     rA   
__delete__zDescriptorProto.__delete__  rN   r@   N)r   r   r   r   rH   r   )r   r   r   r   rH   r4   r   r   rH   r4   )r:   r;   r<   r   r   r   r?   r@   rA   r   r     sP                   r@   r   _DESCc                  2    e Zd ZdZerddZddZddZdS 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   rH   r  c                    d S rK   r?   r   s      rA   r   zDescriptorReference.__get__      Cr@   r   r4   c                    d S rK   r?   r   s      rA   r   zDescriptorReference.__set__  r  r@   c                    d S rK   r?   r   s     rA   r   zDescriptorReference.__delete__  r  r@   N)r   r   r   r   rH   r  )r   r   r   r  rH   r4   r  r:   r;   r<   r=   r   r   r   r   r?   r@   rA   r  r    sn           		 	 	 		 	 	 		 	 	 	 	 		 	r@   r  _DESC_co)r+   r.   c                  2    e Zd ZdZerddZddZddZdS 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   rH   r
  c                    d S rK   r?   r   s      rA   r   zRODescriptorReference.__get__'  r  r@   r   r   c                    d S rK   r?   r   s      rA   r   zRODescriptorReference.__set__*  r  r@   c                    d S rK   r?   r   s     rA   r   z RODescriptorReference.__delete__-  r  r@   N)r   r   r   r   rH   r
  )r   r   r   r   rH   r   )r   r   rH   r   r	  r?   r@   rA   r  r    sn           		 	 	 		 	 	 		 	 	 	 	 		 	r@   r  _FN.c                  2    e Zd ZdZerddZddZddZdS 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   rH   r  c                    d S rK   r?   r   s      rA   r   zCallableReference.__get__?  r  r@   r   r4   c                    d S rK   r?   r   s      rA   r   zCallableReference.__set__B  r  r@   c                    d S rK   r?   r   s     rA   r   zCallableReference.__delete__E  r  r@   N)r   r   r   r   rH   r  )r   r   r   r  rH   r4   r  r	  r?   r@   rA   r  r  4  sn           		 	 	 		 	 	 		 	 	 	 	 		 	r@   r  )rW   rX   rY   rZ   r[   r\   r]   r^   rT   r_   rU   r`   rV   ra   rH   rX   )rY   rv   ru   r7   rH   rD   )rz   r\   r{   r\   r]   r|   rH   r   )r   r\   r{   r\   r]   r|   rH   r   )r   r\   r{   r\   rH   r\   )rW   rX   rY   r6   r[   r\   r]   r^   rT   r_   rH   rX   )r   r   rH   r`   )r   r   rH   r   )r   rZ   rH   r`   )r   r   rH   r   )r   rZ   rH   r   )r   rZ   rH   r   )r   r   rH   rX   )F)r   rZ   r   r`   rH   r   )r   r\   rH   r\   )r   rX   rH   rX   )r   rZ   rH   rZ   )r   r	   rH   rZ   )r   rZ   rH   rX   )FF)r   rX   r   r`   r   r`   rH   r   )r   r   rH   r   )r   r   rH   r`   )r   r   r   r   rH   r`   )r   r   r   r\   r   r   rH   r`   )r   rX   rH   r\   )a
__future__r   r   collections.abcabcr   r   r   typingr   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/   r1   r2   r   r   r3   r   r   r   r   r\   rZ   r6   rC   rG   _LiteralStarrf   rs   rm   r   r   r   r   r   ro   r   rn   r   r   rj   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r?   r@   rA   <module>r     s'   # " " " " "  ) ) ) ) ) ) 				 



                                                                                                                         A888888<<<<<<      100000000000666666::::::444444<<<<<<888888666666@@@@@@888888888888888888......@@@@@@WTgenn	T	*	*	*W\666
genn	T	*	*	* 
<  +******tDzzH
*V

  IsJ8NN 
. . . . .x . . .    hrl   (    Xc6k2    s| ;?!(,C C C C C CL/ / / / ,0	     8 ,0	     D. . . . ;?     ,G G G G   ( ( ( (+ + + +G G G G, , , ,    7<     
   
 
   
 
   
   .   >/ / / / IN    (   E E E E( ( ( (
F 
F 
F 
F 6:            h    	///    '%.   . 7:_EEE    GH-   ( ge8HS#X$67888         r@   