File: //usr/local/lib/python3.10/dist-packages/sqlalchemy/ext/mypy/__pycache__/infer.cpython-310.pyc
o
���g�K � @ s� d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z d dlm
Z
d dlmZ d d lmZ d d
lm
Z
d dlmZ d dlmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ ddl 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
�returnc C s� t �|�}|d u rd S |t ju rt| ||||�}|S |t ju r(t| |||�}|S |t ju r6t| |||�}|S |t ju rDt | |||�}|S |t j
u rQt| ||�}|S |t ju r_t
| |||�}|S d S �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)r r r 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
�
��
��
��
��
���r7 c
C sZ t |jt�sJ �|jjd }d}t |t�r#t |jt�r#|j}t|g �}t� |jd�}t� |jd�}d} |durQ| �
|�du rQ|du rQd} |durP| �tj
|g�}n�|du s\| �
|�du r�|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�| �
|�du r�|dur�t�| d|j� |dur�t|t� g�}n|du r�d }t�| |�|j�|� |du �rt| ||�S |du�r+| �r$t |t��sJ �t |t��sJ �t| |||�S t| |||�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"]
r N�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 r r r �get_callexpr_kwarg�
parse_bool�
named_typer �NAMED_TYPE_BUILTINS_LIST�calleer �typer r �ret_type�failr r �format�namer0 �3_infer_collection_type_from_left_and_inferred_right�(_infer_type_from_left_and_inferred_right)
r r r r! �target_cls_argr4 �related_object_type�uselist_arg�collection_cls_arg�type_is_a_collection�rt�callable_ret_type�msgr5 r5 r6 r, P s� �
���
����
�
�������
�
��r, c C sz t |jt�sJ �|jjd }d}t |t�r$t |jt�r$|j}t|g �}nd}|du r0t| ||�S |dur;t | |||�S |S )z+Infer the type of mapping from a Composite.r N)
r: r; r r<