HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/util/__pycache__/typing.cpython-310.pyc
o

���g�Q�@s�ddlmZddlZddlmZddlmZddlZddl	Z	ddl
Z
ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddlmZ	ddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&dd lm'Z'dd!lm(Z(dd"lm)Z)dd#lm*Z*dd$lm+Z+dd%lm,Z,dd&lm-Z-dd'lm.Z.dd(lm/Z/dd)lm0Z0dd*lm1Z1ed+ed,�Z2ed-�Z3ed.dd/�Z4ed0dd1�Z5ed2�Z6ed3dd/�Z7ej8�r-e9e
j'e'g�Z:ne9e'g�Z:ej;�r=dd4l<m=Z=ne>d�Z=ed5�Z?eeee@eee0d6fZAGd7d8�d8e*�ZBGd9d:�d:e*e2�ZCGd;d<�d<e*e3e7f�ZDe'd=ZEdd>dd?�d�dOdP�ZFd�dRdS�ZGd�dXdY�ZHdddZ�d�dadb�ZIddc�d�dedf�ZJd�dgdh�ZKd�djdk�ZLd�dndo�ZMd�dpdq�ZNd�dtdu�ZOd�dwdx�ZPd�dzd{�ZQd�d}d~�ZRd�d�d��ZS	>	>d�d�d�d��ZTed�d�d���ZUed�d�d���ZUed�d�d���ZUd�d�d��ZUed�d�d���ZVed�d�d���ZVd�d�d��ZVd�d�d��ZWd�d�d��ZXd�d�d��ZYd�d�d��ZZdd��d�d�d��Z[d�d�d��Z\Gd�d��d�e*�Z]ed�e]d,�Z^Gd�d��d�ee^�Z_ed�e]dd��Z`Gd�d��d�ee`�Zaed�eed�efd,�ZbGd�d��d�eeb�ZcdS)��)�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�NonezGenericProtocol[Any]c@seZdZUdZded<dS)�ArgsTypeProtocolz_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?�A/usr/local/lib/python3.10/dist-packages/sqlalchemy/util/typing.pyr6Zs
r6c@s"eZdZUdZded<ded<dS)�GenericProtocolzXprotocol for generic types.

    this since Python.typing _GenericAlias is private

    r7r8�Type[_T]�
__origin__Nr9r?r?r?r@rAds
rAc@s eZdZddd�Zddd	�Zd
S)
�SupportsKeysAndGetItem�return�
Iterable[_KT]cC�dS�Nr?)�selfr?r?r@�keysy�zSupportsKeysAndGetItem.keys�_SupportsKeysAndGetItem__kr-r3cCrGrHr?)rIrLr?r?r@�__getitem__{rKz"SupportsKeysAndGetItem.__getitem__N)rErF)rLr-rEr3)r:r;r<rJrMr?r?r?r@rDxs
rD�*F��str_cleanup_fn�include_generic�
_already_seen�cls�	Type[Any]�
annotation�_AnnotationScanType�originating_module�str�locals_�Mapping[str, Any]rP�#Optional[Callable[[str, str], str]]rQ�boolrR�Optional[Set[Any]]rEc	s�|}t|�r	|j}t|t�r�r�|��}t|���d�}�rOt|�rOt|�sO�dur.t��|�vr4|S��|�t	������fdd�|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.

    �rY�in_classNc
3s&�|]}t�|�����d�VqdS)rON)�de_stringify_annotation��.0�elem�rRrSrQrYrWrPr?r@�	<genexpr>�s�
��
�z*de_stringify_annotation.<locals>.<genexpr>)�
is_fwd_ref�__forward_arg__�
isinstancerX�eval_expression�
is_generic�
is_literal�set�add�tupler8�_copy_generic_annotation_with)	rSrUrWrYrPrQrR�original_annotation�elementsr?rdr@r`�s2

����

�

r`�type_c	Csbt|�r/t|�ttttjtjtjtj	tj
fvr/t�dt
|��s/t|��tdd�t|�D���S|S)zfCorrect dict['x', 'y'] into dict[ForwardRef('x'), ForwardRef('y')]
    and similar for list, set

    z3typing.(?:Dict|List|Set|.*Mapping|.*Sequence|.*Set)cSs"g|]
}t|t�r
t|�n|�qSr?)rhrXr	rar?r?r@�
<listcomp>�s��z,fixup_container_fwd_refs.<locals>.<listcomp>)rjr�dictrl�list�collections_abc�
MutableSet�MutableMapping�MutableSequencer�Sequence�re�match�repr�__class_getitem__rnr�rrr?r?r@�fixup_container_fwd_refs�s2	��������r��GenericProtocol[_T]rqr7rBcCst|d�r
|�|�S|j|S)N�	copy_with)�hasattrr�rC)rUrqr?r?r@ro�s


ror^�
expression�module_name�Optional[Mapping[str, Any]]r_�Optional[Type[Any]]rc	
Cs�ztj|j}Wnty}ztd|�d|���|�d}~wwz'|dur?t|j�}|�|j|�|�|�t	|||�}W|St	|||�}W|St
y[}ztd|���|�d}~ww)N�Module z9 isn't present in sys.modules; can't evaluate expression z"Could not de-stringify annotation )�sys�modules�__dict__�KeyError�	NameErrorrt�
setdefaultr:�update�eval�	Exception)	r�r�rYr_�base_globals�ke�
cls_namespacerU�errr?r?r@ri�s:�����

������ri�rY�namecCs�d|vrt|||d�Sztj|j}Wnty*}ztd|�d|���|�d}~wwz||WSty]}z!ztj|WWYd}~StyMYnwtd|�d|���|�d}~ww)N�.r�r�z2 isn't present in sys.modules; can't resolve name zCould not locate name z in module )rir�r�r�r�r��builtins)r�r�rYr�r�r?r?r@�eval_name_only!s:�����	
�����r�cCs2zt||�}Wnty|YSwt|d|�S)Nr:)r�r��getattr)r�r��objr?r?r@�resolve_name_to_real_class_nameCs�r��
Optional[Any]cCs|duo	t|�tuSrH)rrrr?r?r@�	is_pep593L�r�r��TypeGuard[Iterable[Any]]cCst|tj�o
t|ttf�SrH)rhrvrrX�bytes)r�r?r?r@�is_non_string_iterablePs�r�cCst|�tvSrH)r�
LITERAL_TYPESrr?r?r@rkV�rk�Optional[_AnnotationScanType]�TypeGuard[NewType]cCs
t|d�S)N�
__supertype__�r�rr?r?r@�
is_newtypeZ�
r��TypeGuard[GenericProtocol[Any]]cCst|d�o	t|d�S)Nr8rCr�rr?r?r@rjbr�rj�TypeGuard[TypeAliasType]cCs
t|t�SrH)rhr)rr?r?r@�	is_pep695fr�r�r
cCs |j}t|�r|j}t|�s|SrH)r�r�)rr�
super_typer?r?r@�flatten_newtypejs
�r��Set[Any]cs~t����fdd���|�}t|t�r<t�}t|�}|r:|��}t|t�r+|�|�n
|�|tthvr5dn|�|s|S|hS)z�Extracts 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.
    csH|�vr|S��|�t|�s|S|j}t|�s|S�fdd�|jD�S)Ncsg|]}�|��qSr?r?�rb�t)�recursive_valuer?r@rs�sz:pep695_values.<locals>.recursive_value.<locals>.<listcomp>)rmr��	__value__�is_unionr8)rr�value��_seenr�r?r@r�zs
z&pep695_values.<locals>.recursive_valueN)	rlrhrur�popleft�extendrmr4�NoneFwd)rr�res�types�stackr�r?r�r@�
pep695_valuesqs

�r��
check_generic�check_for_plain_string�TypeGuard[ForwardRef]csH�r	t|t�r	dSt|t�rdS|r"t|�r"t�fdd�|jD��SdS)NTc3s�|]
}t|d�d�VqdS)T�r�N)rf)rb�argr�r?r@re�s���
�zis_fwd_ref.<locals>.<genexpr>F)rhrXr	rj�anyr8)rrr�r�r?r�r@rf�s
�rfcCrGrHr?rr?r?r@�de_optionalize_union_types��r�cCrGrHr?rr?r?r@r��r�cCrGrHr?rr?r?r@r���cCs�t|�r	t|d�St|�rRt|�rRtjrt|j�}n*t|g�}t�}|r?|�	�}|jD]}t|�r7|�
|�q+|�|�q+|s$|�d�|�t
�|�t�t|�S|S)z�Given 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)rf�#_de_optionalize_fwd_ref_union_typesr��
includes_noner�py39rlr8rr��appendrm�discardr4r��make_union_type)rr�typ�stack_of_unions�u_typrcr?r?r@r��s&


�


r	�return_has_none�
Literal[True]cCrGrHr?�rrr�r?r?r@r��r�r��Literal[False]cCrGrHr?r�r?r?r@r��r�� Union[_AnnotationScanType, bool]c
Csp|j}t�d|�}|r�|�d��d�d}|dkr$|rdSt|�d��S|dkr�d	|�d�vrlg}g}d
}|�d�D]0}|d	krE|d7}n |dkrN|d8}n|d
kre|dkre|�d
�|����|�	�q:|�|�q:n	t�d|�d��}dd�|D�}	|r�t
|�t
|	�kS|	r�t|	�StS|r�dS|St�d|�}
d|
v}|r�|S|r�d�dd�|
D��}|r�t|�StS|S)z�return 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^(.+?)\[(.+)\]$rr����rT�r�[r�]�,�z,\s*cSsg|]
}|dkrt|��qS)r5rrar?r?r@rssz7_de_optionalize_fwd_ref_union_types.<locals>.<listcomp>Fz\s*\|\s*r5�|css�|]	}|dkr|VqdS)r5Nr?)rb�pr?r?r@res�z6_de_optionalize_fwd_ref_union_types.<locals>.<genexpr>)
rgr{r|�group�splitr	r��join�strip�clear�lenr�r*)
rrr�rU�mm�g1rq�current�ignore_comma�char�parts�pipe_tokens�has_none�anno_strr?r?r@r��sH


�r�cGs
t�|�S)zMake a Union type.)rrM)r�r?r?r@r�#s
r�cCs�t|�r	t|d�St|�rtdd�t|�D��St|�r$tt|�d�St|�r3tdd�t|�D��St	|�r<t|j
�S|ttdfvS)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
    Tcs��|]}t|�VqdSrH�r�r�r?r?r@re7��z includes_none.<locals>.<genexpr>rcsr�rHr�r�r?r?r@re;r�N)
rfr�r�r�rr�r�r�r�r�r�r�r4rr?r?r@r�(s

r��TypeGuard[ArgsTypeProtocol]cCst|dd�S)Nr�	UnionType)�is_origin_ofrr?r?r@r�Ar�r��	class_obj�'Union[Tuple[Type[Any], ...], Type[Any]]cCs(t|�}|dur
dSt|t�ot||�S)z[return True if the given type has an __origin__ that shares a base
    with the given classNF)rrh�type�
issubclass)rrr��originr?r?r@�is_origin_of_clsEsr�)�module�namesr��
Optional[str]cGs4t|�}|dur
dSt|�|vo|dup|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)rrr�r�r�r?r?r@r�Rs�r�cCs0tjr|jSt|dd�}|durt|dd�}|S)Nr:�_name)r�py310r:r�)rr�typ_namer?r?r@r�asr�c@s*eZdZddd�Zdd
d�Zddd
�ZdS)�DescriptorProto�instance�object�ownerrrEcCrGrHr?�rIrrr?r?r@�__get__mrKzDescriptorProto.__get__r�r5cCrGrHr?�rIrr�r?r?r@�__set__orKzDescriptorProto.__set__cCrGrHr?�rIrr?r?r@�
__delete__qrKzDescriptorProto.__delete__N)rrrrrEr)rrr�rrEr5�rrrEr5)r:r;r<rr
rr?r?r?r@rls

r�_DESCc@�6eZdZdZerddd	�Zddd
�Zddd�ZdSdS)�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

    rrrrrErcCrGrHr?rr?r?r@r�rKzDescriptorReference.__get__r�r5cCrGrHr?r	r?r?r@r
�rKzDescriptorReference.__set__cCrGrHr?rr?r?r@r�rKzDescriptorReference.__delete__N)rrrrrEr)rrr�rrEr5r
�r:r;r<r=rrr
rr?r?r?r@rws


�r�_DESC_co)r,r/c@r)�RODescriptorReferencez�a 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

    rrrrrErcCrGrHr?rr?r?r@r�rKzRODescriptorReference.__get__r�rcCrGrHr?r	r?r?r@r
�rKzRODescriptorReference.__set__cCrGrHr?rr?r?r@r�rKz RODescriptorReference.__delete__N)rrrrrEr)rrr�rrEr)rrrErrr?r?r?r@r�s

�r�_FN.c@r)�CallableReferencez�a descriptor that refers to a callable.

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


    rrrrrErcCrGrHr?rr?r?r@r�rKzCallableReference.__get__r�r5cCrGrHr?r	r?r?r@r
�rKzCallableReference.__set__cCrGrHr?rr?r?r@r�rKzCallableReference.__delete__N)rrrrrEr)rrr�rrEr5r
rr?r?r?r@r�s

�r)rSrTrUrVrWrXrYrZrPr[rQr\rRr]rErT)rrrVrErV)rUr�rqr7rErB)
r�rXr�rXrYr�r_r�rEr)r�rXr�rXrYr�rEr)r�rXr�rXrErX)rrr�rEr\)r�rrEr�)rrrrEr\)rrr�rEr�)rrrVrEr�)rrrVrEr�)rrr
rErT)rrrVrEr�)FF)rrrVr�r\r�r\rEr�)rrrXrErX)rrrTrErT)rrr	r�r�rEr\)rrr	r�r�rErV)rrr	r�r\rEr�)r�rVrErT)rrrrEr�)rrrr�r�rEr\)rrrr�rXr�r�rEr\)rrrTrErX)d�
__future__rr��collectionsr�collections.abc�abcrvr{r��typingrrrrr	r
rrr
rrrrrrrrrr�r�typing_extensionsrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r-r.r0r2r3�py38�	frozensetr�rr�r4r�r�rXrVr6rArD�_LiteralStarr`r�rorir�r�r�r�rkr�rjr�r�r�rfr�r�r�r�r�r�r�r�rrrrrrrr?r?r?r@�<module>s�
�
	�
G
)�(�
"
	






'�
)

6


�