o
    )fA                     @  s|  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	d*Z/ed+Z0ed,dd-Z1ed.dd/Z2ed0Z3ed1dd-Z4ej5r d d2l6m7Z7 ne8dZ7ed3Z9e#Z:e$Z;eee	 e<eee.d4f Z=G d5d6 d6e(Z>G d7d8 d8e(e/ Z?G d9d: d:e(e0e4f Z@e%d; ZAdd<dd=ddMdNZBddSdTZCdddUdd\d]ZDdd^dd`daZEddbdcZFdddddedfZGddidjZHddmdnZIddodpZJddrdsZKddudvZLddxdyZMdd{d|ZN	<ddddZOedddZPedddZPedddZPdddZPdddZQdddZR	<ddddZSdddZTdddZUdddZVdddZWdddddZXdddZYG dd de(ZZedeZd*Z[G dd dee[ Z\edeZddZ]G dd dee] Z^edee
de	f  d*Z_G dd 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                   @  s   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__ r=   r=   S/var/www/html/flask-app/venv/lib/python3.12/site-packages/sqlalchemy/util/typing.pyr4   T   s   
 r4   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

    r5   r6   Type[_T]
__origin__Nr7   r=   r=   r=   r>   r?   ^   s   
 r?   c                   @  s    e Zd ZdddZddd	Zd
S )SupportsKeysAndGetItemreturnIterable[_KT]c                 C     d S Nr=   )selfr=   r=   r>   keyss       zSupportsKeysAndGetItem.keys_SupportsKeysAndGetItem__kr+   r1   c                 C  rE   rF   r=   )rG   rJ   r=   r=   r>   __getitem__u   rI   z"SupportsKeysAndGetItem.__getitem__N)rC   rD   )rJ   r+   rC   r1   )r8   r9   r:   rH   rK   r=   r=   r=   r>   rB   r   s    
rB   *Fstr_cleanup_fninclude_generic_already_seencls	Type[Any]
annotation_AnnotationScanTypeoriginating_modulestrlocals_Mapping[str, Any]rN   #Optional[Callable[[str, str], str]]rO   boolrP   Optional[Set[Any]]rC   c          	        s   |}t |r	|j}t|trr|}t|d}rOt|rOt|sO du r.t  | v r4|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   rQ   rO   rW   rU   rN   r=   r>   	<genexpr>   s    

z*de_stringify_annotation.<locals>.<genexpr>)
is_fwd_ref__forward_arg__
isinstancerV   eval_expression
is_generic
is_literalsetaddtupler6   _copy_generic_annotation_with)	rQ   rS   rU   rW   rN   rO   rP   original_annotationelementsr=   rc   r>   r_   |   s2   




r_   GenericProtocol[_T]rp   r5   r@   c                 C  s   t | dr
| |S | j| S )N	copy_with)hasattrrr   rA   )rS   rp   r=   r=   r>   rn      s   


rn   r\   
expressionmodule_nameOptional[Mapping[str, Any]]r]   Optional[Type[Any]]r   c          	   
   C  s   zt j| j}W n ty } ztd| d|  |d }~ww z'|d ur?t|j}||j| || t	| ||}W |S t	| ||}W |S  t
y[ } ztd| |d }~w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
setdefaultr8   updateeval	Exception)	rt   ru   rW   r]   base_globalskecls_namespacerS   errr=   r=   r>   rh      s:   

rh   rW   namec                C  s   d| v rt | ||dS ztj| j}W n ty* } ztd| d|  |d }~ww z||  W S  ty] } z!ztj|  W W  Y d }~S  tyM   Y nw td|  d| |d }~ww )N.r   rx   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rh   ry   rz   r{   r|   r}   builtins)r   ru   rW   r   r   r=   r=   r>   eval_name_only   s:   	
r   c                 C  s2   zt | |}W n ty   |  Y S w t|d| S )Nr8   )r   r}   getattr)r   ru   objr=   r=   r>   resolve_name_to_real_class_name  s   r   rN   c                  s   t  fdd|jD  S )Nc              	     s   g | ]}t  |i d qS )r   r^   )ra   annorQ   rU   rN   r=   r>   
<listcomp>%  s    z/de_stringify_union_elements.<locals>.<listcomp>)make_union_typer6   )rQ   rS   rU   rW   rN   r=   r   r>   de_stringify_union_elements  s
   r   type_Optional[_AnnotationScanType]c                 C  s   | d uo	t | tu S rF   )typing_get_originr   r   r=   r=   r>   	is_pep5932     r   r   TypeGuard[Iterable[Any]]c                 C  s   t | tjot | ttf S rF   )rg   collections_abcr
   rV   bytes)r   r=   r=   r>   is_non_string_iterable6  s   r   c                 C  s   t | tu S rF   )r   r   r   r=   r=   r>   rj   <  s   rj   TypeGuard[NewType]c                 C  
   t | dS )N__supertype__rs   r   r=   r=   r>   
is_newtype@     
r   TypeGuard[GenericProtocol[Any]]c                 C  s   t | do	t | dS )Nr6   rA   r   r   r=   r=   r>   ri   H  r   ri   TypeGuard[TypeAliasType]c                 C  s
   t | tS rF   )rg   r(   r   r=   r=   r>   	is_pep695L  r   r   r   c                 C  s    | j }t|r|j }t|s|S rF   )r   r   )r   
super_typer=   r=   r>   flatten_newtypeP  s
   r   check_genericTypeGuard[ForwardRef]c                 C  s2   t | trdS |rt| rtdd | jD S dS )NTc                 s  s    | ]}t |d V  qdS )TN)re   )ra   argr=   r=   r>   rd   ]  s    zis_fwd_ref.<locals>.<genexpr>F)rg   r   ri   anyr6   )r   r   r=   r=   r>   re   W  s
   
re   c                 C  rE   rF   r=   r   r=   r=   r>   de_optionalize_union_typesb     r   c                 C  rE   rF   r=   r   r=   r=   r>   r   f  r   c                 C  rE   rF   r=   r   r=   r=   r>   r   j  s   c                 C  sB   t | rt| S t| rt| j}|t |t t| S | S )zmGiven a type, filter out ``Union`` types that include ``NoneType``
    to not include the ``NoneType``.

    )	re   "de_optionalize_fwd_ref_union_typesis_optionalrk   r6   discardr2   NoneFwdr   )r   typr=   r=   r>   r   p  s   


r   c                 C  s   | j }td|}|r4|ddkrt|dS |ddkr2td|d}tdd |D  S | S td	|}d
|v rJtd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                 S  s   g | ]
}|d krt |qS )r3   r   r`   r=   r=   r>   r     s    z6de_optionalize_fwd_ref_union_types.<locals>.<listcomp>z\s*\|\s*r3   |c                 s  s    | ]	}|d kr|V  qdS )r3   Nr=   )ra   pr=   r=   r>   rd     s    z5de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)rf   rematchgroupr   splitr   join)r   rS   mmrp   pipe_tokensr=   r=   r>   r     s   
r   typesc                  G  s   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   rK   )r   r=   r=   r>   r     s   r   include_uniondiscard_noneTuple[Type[Any], ...]c                 C  s@   t | rt| j}|r|t |r| ft| S t|S | fS )zPReturn a type as a tuple of individual types, expanding for
    ``Union`` types.)is_unionrk   r6   r   r2   rm   )r   r   r   r   r=   r=   r>   expand_unions  s   

r   TypeGuard[ArgsTypeProcotol]c                 C  s   t | dddS )Nr   r   	UnionTypeis_origin_ofr   r=   r=   r>   r     s   r   c                 C  s   t | o	tt| v S rF   )r   r2   typing_get_argsr   r=   r=   r>   is_optional_union  r   r   c                 C  r   )Nr   r   r   r=   r=   r>   r     r   r   	class_obj'Union[Tuple[Type[Any], ...], Type[Any]]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   rg   type
issubclass)r   r   originr=   r=   r>   is_origin_of_cls  s   r   )modulenamesr   Optional[str]c                G  s4   t | }|du r
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_namer9   
startswith)r   r   r   r   r=   r=   r>   r     s   r   c                 C  s0   t jr| jS t| dd }|d u rt| dd }|S )Nr8   _name)r   py310r8   r   )r   typ_namer=   r=   r>   r     s   r   c                   @  s*   e Zd ZdddZdd
dZdddZdS )DescriptorProtoinstanceobjectownerr   rC   c                 C  rE   rF   r=   rG   r   r   r=   r=   r>   __get__  rI   zDescriptorProto.__get__valuer3   c                 C  rE   rF   r=   rG   r   r   r=   r=   r>   __set__  rI   zDescriptorProto.__set__c                 C  rE   rF   r=   rG   r   r=   r=   r>   
__delete__  rI   zDescriptorProto.__delete__N)r   r   r   r   rC   r   )r   r   r   r   rC   r3   r   r   rC   r3   )r8   r9   r:   r   r   r   r=   r=   r=   r>   r     s    

r   _DESCc                   @  6   e Zd ZdZerddd	ZdddZd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   rC   r   c                 C  rE   rF   r=   r   r=   r=   r>   r     rI   zDescriptorReference.__get__r   r3   c                 C  rE   rF   r=   r   r=   r=   r>   r     rI   zDescriptorReference.__set__c                 C  rE   rF   r=   r   r=   r=   r>   r     rI   zDescriptorReference.__delete__N)r   r   r   r   rC   r   )r   r   r   r   rC   r3   r   r8   r9   r:   r;   r   r   r   r   r=   r=   r=   r>   r     s    


r   _DESC_co)r*   r-   c                   @  r   )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   rC   r   c                 C  rE   rF   r=   r   r=   r=   r>   r   (  rI   zRODescriptorReference.__get__r   r   c                 C  rE   rF   r=   r   r=   r=   r>   r   *  rI   zRODescriptorReference.__set__c                 C  rE   rF   r=   r   r=   r=   r>   r   ,  rI   z RODescriptorReference.__delete__N)r   r   r   r   rC   r   )r   r   r   r   rC   r   )r   r   rC   r   r   r=   r=   r=   r>   r     s    

r   _FN.c                   @  r   )CallableReferenceza descriptor that refers to a callable.

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


    r   r   r   r   rC   r   c                 C  rE   rF   r=   r   r=   r=   r>   r   =  rI   zCallableReference.__get__r   r3   c                 C  rE   rF   r=   r   r=   r=   r>   r   ?  rI   zCallableReference.__set__c                 C  rE   rF   r=   r   r=   r=   r>   r   A  rI   zCallableReference.__delete__N)r   r   r   r   rC   r   )r   r   r   r   rC   r3   r   r   r=   r=   r=   r>   r   2  s    

r   )rQ   rR   rS   rT   rU   rV   rW   rX   rN   rY   rO   rZ   rP   r[   rC   rR   )rS   rq   rp   r5   rC   r@   )
rt   rV   ru   rV   rW   rv   r]   rw   rC   r   )r   rV   ru   rV   rW   rv   rC   r   )r   rV   ru   rV   rC   rV   )rQ   rR   rS   r4   rU   rV   rW   rX   rN   rY   rC   rR   )r   r   rC   rZ   )r   r   rC   r   )r   rT   rC   rZ   )r   r   rC   r   )r   rT   rC   r   )r   rT   rC   r   )r   r   rC   rR   )F)r   rT   r   rZ   rC   r   )r   rV   rC   rV   )r   rR   rC   rR   )r   rT   rC   rT   )r   r   rC   rT   )r   rT   rC   rR   )FF)r   rR   r   rZ   r   rZ   rC   r   )r   r   rC   r   )r   r   rC   rZ   )r   r   r   r   rC   rZ   )r   r   r   rV   r   r   rC   rZ   )r   rR   rC   rV   )a
__future__r   r   collections.abcabcr   r   ry   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   rV   rT   r4   r?   rB   _LiteralStarr_   rn   rh   r   r   r   r   r   rj   r   ri   r   r   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r=   r=   r>   <module>   s   
	
F(
"











	


