
    hA                       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jj                  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=	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 djd>ZB	 	 	 	 	 	 dkd?ZCddd@	 	 	 	 	 	 	 	 	 dldAZDddB	 	 	 	 	 	 	 dmdCZEdndDZFddE	 	 	 	 	 	 	 	 	 	 	 dodFZGdpdGZHdqdHZIdrdIZJdsdJZKdtdKZLdudLZMdvdMZN	 dw	 	 	 	 	 dxdNZOedydO       ZPedzdP       ZPe	 	 	 	 d{dQ       ZP	 	 	 	 d{dRZP	 	 	 	 d|dSZQd}dTZR	 d~	 	 	 	 	 	 	 ddUZSddVZTddWZUddXZV	 	 	 	 	 	 ddYZWddZ	 	 	 	 	 	 	 dd[ZXdd\ZY G d] d^e(      ZZ ed_eZ*      Z[ G d` daee[         Z\ edbeZdc      Z] G dd deee]         Z^ edfee
dge	f      *      Z_ G dh diee_         Z`y)    )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<   y)ArgsTypeProcotolz_protocol for types that have ``__args__``

    there's no public interface for this AFAIK

    Tuple[_AnnotationScanType, ...]__args__N__name__
__module____qualname____doc____annotations__     a/var/www/html/retail-simulation-api/retail/lib/python3.12/site-packages/sqlalchemy/util/typing.pyr5   r5   T   s     .-r?   r5   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

    r6   r7   Type[_T]
__origin__Nr8   r>   r?   r@   rB   rB   ^   s     .-r?   rB   c                      e Zd ZddZddZy)SupportsKeysAndGetItemc                     y Nr>   )selfs    r@   keyszSupportsKeysAndGetItem.keyss   s    Sr?   c                     y rH   r>   )rI   _SupportsKeysAndGetItem__ks     r@   __getitem__z"SupportsKeysAndGetItem.__getitem__u   s    sr?   N)returnzIterable[_KT])rL   r+   rN   r1   )r9   r:   r;   rJ   rM   r>   r?   r@   rF   rF   r   s    (2r?   rF   *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)rP   N)de_stringify_annotation).0elemrS   clsrR   rV   originating_modulerQ   s     r@   	<genexpr>z*de_stringify_annotation.<locals>.<genexpr>   s<      
 , $"- /+  ,s   )
is_fwd_ref__forward_arg__
isinstancestreval_expression
is_generic
is_literalsetaddtupler7   _copy_generic_annotation_with)	r\   
annotationr]   rV   rQ   rR   rS   original_annotationelementss	   ` `````  r@   rY   rY   |   s    . %*//
*c"'
4FGJ$*Gc


 	z":& EM&
 '&j) 
 
 #++
 
 -ZBBr?   c                Z    t        | d      r| j                  |      S | j                  |   S )N	copy_with)hasattrrn   rD   )rj   rl   s     r@   ri   ri      s2     z;'##H-- $$X..r?   rU   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	NameErrordict
setdefaultr9   updateeval	Exception)	
expressionmodule_namerV   rW   base_globalskecls_namespacerj   errs	            r@   rc   rc      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rV   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   rq   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rc   rr   rs   rt   ru   rv   builtins)namer}   rV   r~   r   s        r@   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)Nr9   )r   getattrrv   )r   r}   objs      r@   resolve_name_to_real_class_namer     s:    .T;/ sJ--  s    ))rQ   c               h    t        |j                  D cg c]  }t        | ||i |       c} S c c}w )Nr   )make_union_typer7   rY   )r\   rj   r]   rV   rQ   annos         r@   de_stringify_union_elementsr     sQ      #++	

 , $"- ,	

 	

s   /c                0    | d uxr t        |       t        u S rH   )typing_get_originr   type_s    r@   	is_pep593r   2  s    F!25!9Y!FFr?   c                h    t        | t        j                        xr t        | t        t        f       S rH   )ra   collections_abcr
   rb   bytes)r   s    r@   is_non_string_iterabler   6  s1    c?334 Zc5\> : r?   c                $    t        |       t        u S rH   )r   r   r   s    r@   re   re   <  s    e''r?   c                    t        | d      S )N__supertype__ro   r   s    r@   
is_newtyper   @  s    5/**r?   c                6    t        | d      xr t        | d      S )Nr7   rD   r   r   s    r@   rd   rd   H  s    5*%F'%*FFr?   c                "    t        | t              S rH   )ra   r(   r   s    r@   	is_pep695r   L  s    e]++r?   c                d    | j                   }t        |      r|j                   }t        |      r|S rH   )r   r   )r   
super_types     r@   flatten_newtyper   P  s0    $$J
Z
 --
 Z
 r?   c                x    t        | t              ry|r't        |       rt        d | j                  D              S y)NTc              3  4   K   | ]  }t        |d         yw)TN)r_   )rZ   args     r@   r^   zis_fwd_ref.<locals>.<genexpr>]  s     CNS:c4(Ns   F)ra   r   rd   anyr7   )r   check_generics     r@   r_   r_   W  s3     %$	:e,CENNCCCr?   c                     y rH   r>   r   s    r@   de_optionalize_union_typesr   b  s    36r?   c                     y rH   r>   r   s    r@   r   r   f  s    ?Br?   c                     y rH   r>   r   s    r@   r   r   j  s     r?   c                    t        |       rt        |       S t        |       rGt        | j                        }|j                  t               |j                  t               t        | S | S )zmGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    )	r_   "de_optionalize_fwd_ref_union_typesis_optionalrf   r7   discardr2   NoneFwdr   )r   typs     r@   r   r   p  sW     %1%88	U	%..!HG$$ r?   c                   | j                   }t        j                  d|      }|r|j                  d      dk(  rt	        |j                  d            S |j                  d      dk(  rJt        j
                  d|j                  d            }t        |D cg c]  }|dk7  s	t	        |       c} S | S t        j
                  d|      }d|v r!t	        d	j                  d
 |D                    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   z,\s*r3   z\s*\|\s*|c              3  ,   K   | ]  }|d k7  s	|  yw)r3   Nr>   )rZ   ps     r@   r^   z5de_optionalize_fwd_ref_union_types.<locals>.<genexpr>  s     "IkQ&[1ks   
)r`   rematchgroupr   splitr   join)r   rj   mmrl   r[   pipe_tokenss         r@   r   r     s     &&J	$j	1B	88A;*$bhhqk**XXa[G#xx!5H"/7Jxt46>*T"xJ  L((;
3K#(("Ik"IIJJL Ks   
C0 C0c                 H    t        t        t              j                  |       S )zMake a Union type.

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

    )r   r   r   rM   )typess    r@   r   r     s     U''..r?   c                    t        |       rHt        | j                        }|r|j                  t               |r| ft        |      z   S t        |      S | fS )zPReturn a type as a tuple of individual types, expanding for
    ``Union`` types.)is_unionrf   r7   r   r2   rh   )r   include_uniondiscard_noner   s       r@   expand_unionsr     sM     %..!KK!8eCj((:xr?   c                    t        | ddd      S )Nr   r   	UnionTypeis_origin_ofr   s    r@   r   r     s    	 r?   c                >    t        |       xr t        t        |       v S rH   )r   r2   typing_get_argsr   s    r@   is_optional_unionr     s    uD(oe.D"DDr?   c                    t        | d      S )Nr   r   r   s    r@   r   r     s    w''r?   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   ra   type
issubclass)r   	class_objorigins      r@   is_origin_of_clsr     s/     u%F~fd#E
69(EEr?   )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       r@   r   r     sJ     u%F~&!U* $>&++66v>r?   c                v    t         j                  r| j                  S t        | dd       }|t        | dd       }|S )Nr9   _name)r   py310r9   r   )r   typ_names     r@   r   r     s:    ||~~5*d3ugt4Hr?   c                  $    e Zd ZddZddZddZy)DescriptorProtoc                     y rH   r>   rI   instanceowners      r@   __get__zDescriptorProto.__get__  s    Cr?   c                     y rH   r>   rI   r   values      r@   __set__zDescriptorProto.__set__  s    #r?   c                     y rH   r>   rI   r   s     r@   
__delete__zDescriptorProto.__delete__  s    r?   N)r   objectr   r   rN   r   )r   r   r   r   rN   r3   r   r   rN   r3   )r9   r:   r;   r   r   r   r>   r?   r@   r   r     s    ?=4r?   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 rH   r>   r   s      r@   r   zDescriptorReference.__get__      #r?   c                     y rH   r>   r   s      r@   r   zDescriptorReference.__set__      r?   c                     y rH   r>   r   s     r@   r   zDescriptorReference.__delete__      Sr?   N)r   r   r   r   rN   r   )r   r   r   r   rN   r3   r   r9   r:   r;   r<   r   r   r   r   r>   r?   r@   r   r     s     EC8 r?   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 rH   r>   r   s      r@   r   zRODescriptorReference.__get__(  s    Sr?   c                     y rH   r>   r   s      r@   r   zRODescriptorReference.__set__*  r   r?   c                     y rH   r>   r   s     r@   r   z RODescriptorReference.__delete__,  s    r?   N)r   r   r   r   rN   r   )r   r   r   r   rN   r   )r   r   rN   r   r   r>   r?   r@   r   r     s     HE< r?   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 rH   r>   r   s      r@   r   zCallableReference.__get__=  r   r?   c                     y rH   r>   r   s      r@   r   zCallableReference.__set__?  s    cr?   c                     y rH   r>   r   s     r@   r   zCallableReference.__delete__A  r   r?   N)r   r   r   r   rN   r   )r   r   r   r   rN   r3   r   r   r>   r?   r@   r   r   2  s     CA8 r?   r   )r\   	Type[Any]rj   _AnnotationScanTyper]   rb   rV   Mapping[str, Any]rQ   #Optional[Callable[[str, str], str]]rR   boolrS   zOptional[Set[Any]]rN   r  )rj   zGenericProtocol[_T]rl   r6   rN   rC   )
r|   rb   r}   rb   rV   Optional[Mapping[str, Any]]rW   zOptional[Type[Any]]rN   r   )r   rb   r}   rb   rV   r	  rN   r   )r   rb   r}   rb   rN   rb   )r\   r  rj   r5   r]   rb   rV   r  rQ   r  rN   r  )r   Optional[_AnnotationScanType]rN   r  )r   r   rN   zTypeGuard[Iterable[Any]])r   r  rN   r  )r   r
  rN   zTypeGuard[NewType])r   r  rN   zTypeGuard[GenericProtocol[Any]])r   r  rN   zTypeGuard[TypeAliasType])r   r   rN   r  )F)r   r  r   r  rN   zTypeGuard[ForwardRef])r   rb   rN   rb   )r   r  rN   r  )r   r  rN   r  )r   r   rN   r  )r   r  rN   r  )FF)r   r  r   r  r   r  rN   zTuple[Type[Any], ...])r   r   rN   zTypeGuard[ArgsTypeProcotol])r   r   rN   r  )r   r   r   z'Union[Tuple[Type[Any], ...], Type[Any]]rN   r  )r   r   r   rb   r   zOptional[str]rN   r  )r   r  rN   rb   )a
__future__r   r   collections.abcabcr   r   rr   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.   r0   r1   r   r   r2   r   r   r   r   rb   r  r5   rB   rF   _LiteralStarrY   ri   rc   r   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>r     sJ   #  ) 	 
                     8< 106:4<86@888.@Ten	T	*\6
en	T	* 
<< +DzH
V
  IsJ8NN 
.x .hrl (3Xc6k2 3 s| ;?!(,C	C#C C 	C 8C C &C CL/#//N// ,0$(!!! )	!
 "! 	!P ,0	
 )	
 	D. ;?	   	 8 ,G(+G, 7</3 
 6 
 6 
 B 
 B 
 

.>/ IN%)AE(E(
F
FB
F	
F 6:%2	5h 5 	/9'%. 9( :_E=GH- =" e8HS#X$6789 9r?   