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/ext/mypy/__pycache__/infer.cpython-310.pyc
o

���g�K�@s�ddlmZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"dGd(d)�Z#dHd*d+�Z$dHd,d-�Z%dGd.d/�Z&dHd0d1�Z'	2dIdJd5d6�Z(	2	2dKdLd;d<�Z)dMd>d?�Z*dNd@dA�Z+dOdEdF�Z,d2S)P�)�annotations)�Optional)�Sequence)�map_instance_to_supertype)�AssignmentStmt)�CallExpr)�
Expression)�FuncDef)�
LambdaExpr)�
MemberExpr)�NameExpr)�RefExpr)�StrExpr)�TypeInfo)�Var)�SemanticAnalyzerPluginInterface)�
is_subtype)�AnyType)�CallableType)�get_proper_type)�Instance)�NoneType)�
ProperType)�	TypeOfAny)�	UnionType�)�names)�util�apir�stmtr�noder�left_hand_explicit_type�Optional[ProperType]�infer_from_right_sider
�returncCs�t�|�}|durdS|tjurt|||||�}|S|tjur(t||||�}|S|tjur6t||||�}|S|tjurDt	||||�}|S|tj
urQt|||�}|S|tjur_t
||||�}|SdS�N)r�type_id_for_callee�MAPPED�_infer_type_from_mapped�COLUMN�_infer_type_from_decl_column�RELATIONSHIP�_infer_type_from_relationship�COLUMN_PROPERTY�%_infer_type_from_decl_column_property�SYNONYM_PROPERTY�#infer_type_from_left_hand_type_only�COMPOSITE_PROPERTY�(_infer_type_from_decl_composite_property)rrr r!r#�type_id�python_type_for_type�r5�D/usr/local/lib/python3.10/dist-packages/sqlalchemy/ext/mypy/infer.py�#infer_type_from_right_hand_nameexpr(sD


�
��
��
��
��

���r7c
CsZt|jt�sJ�|jjd}d}t|t�r#t|jt�r#|j}t|g�}t�	|jd�}t�	|jd�}d}	|durQ|�
|�durQ|durQd}	|durP|�tj
|g�}n�|dus\|�
|�dur�|dur�d}	t|t�rj|j}t|t�r�t|jt�r�|dur�t|j|g�}nyt|t�r�t|jt�r�|jjdur�|dur�t|jjt�r�t|jjj�}
t|
t�r�t|
j�}t|t�r�t|j|g�}n?t�|d|j�d}n4|dur�|�
|�dur�|dur�t�|d|j�|dur�t|t�g�}n|dur�d	}t�||�|j�|�|du�rt|||�S|du�r+|	�r$t|t��sJ�t|t��sJ�t||||�St||||�S|S)
a�Infer the type of mapping from a relationship.

    E.g.::

        @reg.mapped
        class MyClass:
            # ...

            addresses = relationship(Address, uselist=True)

            order: Mapped["Order"] = relationship("Order")

    Will resolve in mypy as::

        @reg.mapped
        class MyClass:
            # ...

            addresses: Mapped[List[Address]]

            order: Mapped["Order"]

    rN�uselist�collection_classFTz>Expected Python collection type for collection_class parameterzOSending uselist=False and collection_class at the same time does not make sensez�Can't infer scalar or collection for ORM mapped expression assigned to attribute '{}' if both 'uselist' and 'collection_class' arguments are absent from the relationship(); please specify a type annotation on the left hand side.)�
isinstance�rvaluer�argsrr rrr�get_callexpr_kwarg�
parse_bool�
named_typer�NAMED_TYPE_BUILTINS_LIST�calleer	�typerr�ret_type�failrr�format�namer0�3_infer_collection_type_from_left_and_inferred_right�(_infer_type_from_left_and_inferred_right)
rrr r!�target_cls_argr4�related_object_type�uselist_arg�collection_cls_arg�type_is_a_collection�rt�callable_ret_type�msgr5r5r6r,Ps��
���
����
�


�������
�
��r,cCszt|jt�sJ�|jjd}d}t|t�r$t|jt�r$|j}t|g�}nd}|dur0t|||�S|dur;t	||||�S|S)z+Infer the type of mapping from a Composite.rN)
r:r;rr<rr rrr0rH)rrr r!rIr4rJr5r5r6r2�s$���r2cCs&t|jt�sJ�t�|�}t|||�S)zVInfer the type of mapping from a right side expression
    that returns Mapped.


    )r:r;rr�type_for_calleer0)rrr r!r#�the_mapped_typer5r5r6r(s


�r(cCs�t|jt�sJ�|jjr+|jjd}t|t�r+t�|j�}|tjur+t|||||d�St|jt�rDt�|jj�}|tj	urDt||||�St
|||�S)z�Infer the type of mapping from a ColumnProperty.

    This includes mappings against ``column_property()`` as well as the
    ``deferred()`` function.

    r)�right_hand_expression)r:r;rr<rr&rAr)r*�QUERY_EXPRESSIONr0)rrr r!�first_prop_argr3r5r5r6r.6s2

�
��r.NrS�Optional[CallExpr]c	Cst|t�sJ�d}|durt|jt�sdS|j}|jdd�D]9}t|t�r5t|jt�r4|j}|j}n%qt|ttf�rIt|j	t
�rH|}d}nqt|tf�rPqt|tf�rWqJ�|dur_dSt|j	t
�r�t
�|j	jt
j�r�t||j	|�}|dur�t||||�St|t�g�St|||�S)a�Infer the type of mapping from a Column.

    E.g.::

        @reg.mapped
        class MyClass:
            # ...

            a = Column(Integer)

            b = Column("b", String)

            c: Mapped[int] = Column(Integer)

            d: bool = Column(Boolean)

    Will resolve in MyPy as::

        @reg.mapped
        class MyClass:
            # ...

            a: Mapped[int]

            b: Mapped[str]

            c: Mapped[int]

            d: Mapped[bool]

    Nr�r5)r:rr;rr<rAr
rrr rrr
r�
mro_has_id�mro�
TYPEENGINE�#extract_python_type_from_typeenginerHrrr0)	rrr r!rSrA�
column_arg�	type_argsr4r5r5r6r*gsP&
�
����r*rr4�orig_left_hand_type�orig_python_type_for_typecCsh|dur|}|dur|}t||�s2|�tj|g�}d}t�||�|jt�||j	�t�||j	��|�|S)z�Validate type when a left hand annotation is present and we also
    could infer the right hand side::

        attrname: SomeType = Column(SomeDBType)

    NzRLeft hand assignment '{}: {}' not compatible with ORM mapped expression of type {})
rr?r�NAMED_TYPE_SQLA_MAPPEDrrDrErF�format_type�options)rr r!r4r^r_�effective_typerPr5r5r6rH�s(
����
rHrcCsl|}|}|jrt|jd�}t|jd�}n|}|}t|ttf�s#J�t|ttf�s,J�t||||||d�S)Nr)r^r_)r<rr:rrrH)rr r!r4r^r_�
left_hand_arg�python_type_argr5r5r6rG�s"�rGcCs<|durd}t�||�|j�|�|�tjttj	�g�S|S)z�Determine the type based on explicit annotation only.

    if no annotation were present, note that we need one there to know
    the type.

    Nz�Can't infer type from ORM mapped expression assigned to attribute '{}'; please specify a Python type or Mapped[<python type>] on the left hand side.)
rrDrErFr?rr`rr�special_form)rr r!rPr5r5r6r0s��r0rr]�Sequence[Expression]cCs�|jdkr2|r2|d}t|t�r+t|jt�r+|jjD]}|jdkr)t|jg�Sqn|�tj	g�S|�
d�s=Jd|��|�d�}|durLt|jt�sNJ�tt|g�|j�}t
|jd�S)Nzsqlalchemy.sql.sqltypes.Enumrz	enum.Enumz"sqlalchemy.sql.type_api.TypeEnginez+could not extract Python type from node: %s���)�fullnamer:r
r rrYrr?r�NAMED_TYPE_BUILTINS_STR�has_base�lookup_fully_qualified_or_nonerrr<)rr r]�	first_arg�base_�type_engine_sym�type_enginer5r5r6r[.s2�
����
��r[)rrrrr rr!r"r#r
r$r")
rrrrr rr!r"r$r"r%)rrrrr rr!r"rSrVr$r")NN)rrr rr!rr4rr^r"r_r"r$r")
rrr rr!rr4rr$r")rrr rr!r"r$r")rrr rr]rgr$r)-�
__future__r�typingrr�mypy.maptyper�
mypy.nodesrrrr	r
rrr
rrr�mypy.pluginr�
mypy.subtypesr�
mypy.typesrrrrrrrr�rrr7r,r2r(r.r*rHrGr0r[r5r5r5r6�<module>sR

(
'
 
 6�h�
*