o
    E6dO?                     @  sD  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) ed(ed)Z*ed*Z+ed+dd,Z,ed-dd.Z-ed/Z.ed0dd,Z/ej0rd d1l1m2Z2 ne3dZ2e	d2Z4eZ5e Z6eee e7e	ed3f Z8G d4d5 d5e$Z9G d6d7 d7e$e* Z:G d8d9 d9e$e+e/f Z;e!d: Z<dd;dd<ddLdMZ=ddRdSZ>ddTddYdZZ?ddTdd\d]Z@dd^d_ZAdd`ddadbZBddedfZCddgdhZDddjdkZEddmdnZFddpdqZG	;dddtduZHeddvdwZIeddxdwZIeddydwZIddzdwZIdd|d}ZJdddZK	;ddddZLdddZMdddZNdddZOdddZPdddddZQdddZRG dd de$ZSedeSd)ZTG dd de
eT ZUedeSddZVG dd de
eV ZWedeedef  d)ZXG dd de
eX ZYd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_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<   mC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/util/typing.pyr3   R   s   
 r3   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

    r4   r5   Type[_T]
__origin__Nr6   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=   keysq      zSupportsKeysAndGetItem.keys_SupportsKeysAndGetItem__kr*   r0   c                 C  rD   rE   r<   )rF   rI   r<   r<   r=   __getitem__t   rH   z"SupportsKeysAndGetItem.__getitem__N)rB   rC   )rI   r*   rB   r0   )r7   r8   r9   rG   rJ   r<   r<   r<   r=   rA   p   s    
rA   *Fstr_cleanup_fninclude_generic_already_seencls	Type[Any]
annotation_AnnotationScanTypeoriginating_modulestrlocals_Mapping[str, Any]rM   #Optional[Callable[[str, str], str]]rN   boolrO   Optional[Set[Any]]rB   c          	        s   |}t |r	|j}t|trr|}t|d}rNt|rNt|sN du r-t  | v r3|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.

    rV   Nc              
   3  s&    | ]}t | d V  qdS )rL   Nde_stringify_annotation.0elemrO   rP   rN   rV   rT   rM   r<   r=   	<genexpr>   s    

z*de_stringify_annotation.<locals>.<genexpr>)
is_fwd_ref__forward_arg__
isinstancerU   eval_expression
is_generic
is_literalsetaddtupler5   _copy_generic_annotation_with)	rP   rR   rT   rV   rM   rN   rO   Zoriginal_annotationelementsr<   ra   r=   r]   |   s2   




r]   GenericProtocol[_T]rm   r4   r?   c                 C  s   t | dr
| |S | j| S )N	copy_with)hasattrro   r@   )rR   rm   r<   r<   r=   rl      s   


rl   r[   
expressionmodule_nameOptional[Mapping[str, Any]]r   c             
   C  s|   zt j| j}W n ty } ztd| d|  |d }~ww z	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eval	Exception)rq   rr   rV   base_globalskerR   errr<   r<   r=   rf      s.   rf   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yG } ztd|  d| |d }~ww )N.r[   rt   z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rf   ru   rv   rw   rx   ry   )r   rr   rV   r|   r}   r<   r<   r=   eval_name_only   s0   	
r   c                 C  s2   zt | |}W n ty   |  Y S w t|d| S )Nr7   )r   ry   getattr)r   rr   objr<   r<   r=   resolve_name_to_real_class_name  s   r   rM   c                  s   t  fdd|jD  S )Nc              	     s   g | ]}t  |i d qS )r   r\   )r_   annorP   rT   rM   r<   r=   
<listcomp>  s    z/de_stringify_union_elements.<locals>.<listcomp>)make_union_typer5   )rP   rR   rT   rV   rM   r<   r   r=   de_stringify_union_elements
  s
   r   type_Optional[_AnnotationScanType]c                 C  s   | d uo	t | tu S rE   )typing_get_originr   r   r<   r<   r=   	is_pep593      r   c                 C  s   t | tu S rE   )r   r   r   r<   r<   r=   rh   $  s   rh   TypeGuard[NewType]c                 C  
   t | dS )N__supertype__rp   r   r<   r<   r=   
is_newtype(     
r   TypeGuard[GenericProtocol[Any]]c                 C  s   t | do	t | dS )Nr5   r@   r   r   r<   r<   r=   rg   0  r   rg   r   c                 C  s    | j }t|r|j }t|s|S rE   )r   r   )r   Z
super_typer<   r<   r=   flatten_newtype4  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)rc   )r_   argr<   r<   r=   rb   A  s    zis_fwd_ref.<locals>.<genexpr>F)re   r   rg   anyr5   )r   r   r<   r<   r=   rc   ;  s
   
rc   c                 C  rD   rE   r<   r   r<   r<   r=   de_optionalize_union_typesF     r   c                 C  rD   rE   r<   r   r<   r<   r=   r   K  r   c                 C  rD   rE   r<   r   r<   r<   r=   r   P  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``.

    )	rc   "de_optionalize_fwd_ref_union_typesis_optionalri   r5   discardr1   NoneFwdr   )r   typr<   r<   r=   r   W  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 )r2   r   r^   r<   r<   r=   r     s    z6de_optionalize_fwd_ref_union_types.<locals>.<listcomp>z\s*\|\s*r2   |c                 s  s    | ]	}|d kr|V  qdS )r2   Nr<   )r_   pr<   r<   r=   rb     s    z5de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)rd   rematchgroupr   splitr   join)r   rR   mmrm   Zpipe_tokensr<   r<   r=   r   n  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   rJ   )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_unionri   r5   r   r1   rk   )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 rE   )r   r1   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   re   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_namer8   
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 )Nr7   _name)r   py310r7   r   )r   Z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   rB   c                 C  rD   rE   r<   rF   r   r   r<   r<   r=   __get__  rH   zDescriptorProto.__get__valuer2   c                 C  rD   rE   r<   rF   r   r   r<   r<   r=   __set__  rH   zDescriptorProto.__set__c                 C  rD   rE   r<   rF   r   r<   r<   r=   
__delete__  rH   zDescriptorProto.__delete__N)r   r   r   r   rB   r   )r   r   r   r   rB   r2   r   r   rB   r2   )r7   r8   r9   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   rB   r   c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   zDescriptorReference.__get__r   r2   c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   zDescriptorReference.__set__c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   zDescriptorReference.__delete__N)r   r   r   r   rB   r   )r   r   r   r   rB   r2   r   r7   r8   r9   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   rB   r   c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   zRODescriptorReference.__get__r   r   c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   zRODescriptorReference.__set__c                 C  rD   rE   r<   r   r<   r<   r=   r     rH   z RODescriptorReference.__delete__N)r   r   r   r   rB   r   )r   r   r   r   rB   r   )r   r   rB   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   rB   r   c                 C  rD   rE   r<   r   r<   r<   r=   r   -  rH   zCallableReference.__get__r   r2   c                 C  rD   rE   r<   r   r<   r<   r=   r   0  rH   zCallableReference.__set__c                 C  rD   rE   r<   r   r<   r<   r=   r   3  rH   zCallableReference.__delete__N)r   r   r   r   rB   r   )r   r   r   r   rB   r2   r   r   r<   r<   r<   r=   r   "  s    

r   )rP   rQ   rR   rS   rT   rU   rV   rW   rM   rX   rN   rY   rO   rZ   rB   rQ   )rR   rn   rm   r4   rB   r?   )rq   rU   rr   rU   rV   rs   rB   r   )r   rU   rr   rU   rV   rs   rB   r   )r   rU   rr   rU   rB   rU   )rP   rQ   rR   r3   rT   rU   rV   rW   rM   rX   rB   rQ   )r   r   rB   rY   )r   rS   rB   rY   )r   r   rB   r   )r   rS   rB   r   )r   r   rB   rQ   )F)r   rS   r   rY   rB   r   )r   rU   rB   rU   )r   rQ   rB   rQ   )r   rS   rB   rS   )r   r   rB   rS   )r   rS   rB   rQ   )FF)r   rQ   r   rY   r   rY   rB   r   )r   r   rB   r   )r   r   rB   rY   )r   r   r   r   rB   rY   )r   r   r   rU   r   r   rB   rY   )r   rQ   rB   rU   )Z
__future__r   r   ru   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r    r   Ztyping_extensionsr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r*   r+   r-   r/   r0   r   r   r1   r   r   r   r   rU   rS   r3   r>   rA   Z_LiteralStarr]   rl   rf   r   r   r   r   rh   r   rg   r   rc   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   r<   r<   r=   <module>   s   
		
F










	


