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__/apply.cpython-310.pyc
o

���g_)�@s�ddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddl"m#Z#ddl"m$Z$dd l%m&Z&dd!l%m'Z'dAd,d-�Z(dBd.d/�Z)dCd7d8�Z*dBd9d:�Z+dDd>d?�Z,d@S)E�)�annotations)�List)�Optional)�Union)�
ARG_NAMED_OPT)�Argument)�AssignmentStmt)�CallExpr)�ClassDef)�MDEF)�
MemberExpr)�NameExpr)�RefExpr)�StrExpr)�SymbolTableNode)�TempNode)�TypeInfo)�Var)�SemanticAnalyzerPluginInterface)�add_method_to_class)�AnyType)�get_proper_type)�Instance)�NoneTyp)�
ProperType)�	TypeOfAny)�UnboundType)�	UnionType�)�infer)�util)�expr_to_mapped_constructor)�NAMED_TYPE_SQLA_MAPPED�clsr
�apir�item�Union[NameExpr, StrExpr]�
attributes�List[util.SQLAlchemyAttribute]�return�Nonec	Cs�t|t�r	|j}nt|t�r|j}ndS|jjD]}t|t�r1t|jdt�r1|jdj|kr1n
qt	�
|d|��|�dS|jdurLt	�
|d|�dSt|j�}t|t
ttf�s[J�|�t	j||j|j||jd��t|||jd|d�dS)NrzCan't find mapped attribute zBStatement linked from _mypy_mapped_attrs has no typing information)�name�line�column�typ�info)�
isinstancer
r+r�value�defs�bodyr�lvaluesr �fail�typerrrr�append�SQLAlchemyAttributer,r-r/�apply_type_to_mapped_statement)r#r$r%r'r+�stmt�left_hand_explicit_type�r<�D/usr/local/lib/python3.10/dist-packages/sqlalchemy/ext/mypy/apply.py�apply_mypy_mapped_attr-sL

���
�

���
�r>c
	Cs�dd�|D�}d}|jjD]�}t|t�r�t|jdt�r�|jdj|vr�t|jdjt�r�|jdj}||jdjj	}t
|j	�}t|t�r�t|t�s�t|jt
�r�t|jjt�r�t|jjjt�r�|jjjjdur�|jjjjjtkr�|jjjdkr�t|jjdt
�r�t|jjdjt�r�t�|||||jjdj�}	|	dur�t|	t�s�|	}|||jdj_	d}t|j	t�r�|j	j	jtkr�|dus�J�|�t|g�|_	q
|r�t�|j|�dSdS)zlFor multiple class passes, re-apply our left-hand side types as mypy
    seems to reset them in place.

    cSsi|]}|j|�qSr<)r+��.0�attrr<r<r=�
<dictcomp>ksz4re_apply_declarative_assignments.<locals>.<dictcomp>FrN�_empty_constructorT)r2r3r0rr4r
r+�noderr6rr�rvaluer	�calleer�expr�fullnamer"�argsrr�#infer_type_from_right_hand_nameexprr�
named_typer �set_mapped_attributesr/)
r#r$r'�mapped_attr_lookup�update_cls_metadatar:�	left_node�python_type_for_type�left_node_proper_type�new_python_type_for_typer<r<r=� re_apply_declarative_assignmentsbs|	���
��
��
��������

��
����rSr:r�lvaluer
r;�Optional[ProperType]rPcCs�|j}t|t�s
J�|durd|_|�t|g�|_nd|_|�t|dur*ttj	�gn|g�|_t
|j�|_|jdurC|durE||_dSdSdS)a�Apply the Mapped[<type>] annotation and right hand object to a
    declarative assignment statement.

    This converts a Python declarative class statement such as::

        class User(Base):
            # ...

            attrname = Column(Integer)

    To one that describes the final Python behavior to Mypy::

    ... format: off

        class User(Base):
            # ...

            attrname : Mapped[Optional[int]] = <meaningless temp node>

    ... format: on

    NF)rDr0r�is_inferred_defrKr"r6rr�special_formr!rE)r$r:rTr;rPrOr<r<r=r9�s$���
�r9c	Cs$t�||�}|durdSt�|�}d|jvrt|stdd�|D�}|jdd�D] }d|jvr.q&t�||�}|dur9q&|D]
}|�|j|j	�q;q&g}	|�
�D]\}
}|durZttj
�}|	�tt|
|�|t|�td��qMt||d|	t��d	|jvr�t�|�r�t||d
d	�|s�t||dd�dSdS)
zCApply __init__, __table__ and other attributes to the mapped class.N�__init__cSsi|]}|j|j�qSr<)r+r6r?r<r<r=rBsz1add_additional_orm_attributes.<locals>.<dictcomp>r����
sqlalchemy)�variable�type_annotation�initializer�kind�	__table__zsqlalchemy.sql.schema.Tablezsqlalchemy.orm.mapper.Mapper�
__mapper__)r �info_for_cls�get_is_base�names�mro�metadata�get_mapped_attributes�
setdefaultr+r6�itemsrrrWr7rrrrrr�
get_has_table� _apply_placeholder_attr_to_class)r#r$r'r/�is_base�mapped_attr_names�base�base_cls_attributesrA�	argumentsr+r.r<r<r=�add_additional_orm_attributes�sJ

�
��	���rp�qualified_name�str�attrnamecCsr|�|�}|rt|jt�sJ�t|jg�}nttj�}t|�}|j	d||_
|j|_||_t
t|�|jj|<dS)N�.)�lookup_fully_qualified_or_noner0rDrrrrrWrrH�	_fullnamer/r6rrrc)r$r#rqrs�sym�type_�varr<r<r=rj4s

rjN)
r#r
r$rr%r&r'r(r)r*)r#r
r$rr'r(r)r*)r$rr:rrTr
r;rUrPrUr)r*)
r$rr#r
rqrrrsrrr)r*)-�
__future__r�typingrrr�
mypy.nodesrrrr	r
rrr
rrrrrr�mypy.pluginr�mypy.plugins.commonr�
mypy.typesrrrrrrrr�rr rcr!r"r>rSr9rprjr<r<r<r=�<module>sJ

5
U
H5