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

���g�C�@s�ddlmZddlmZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#d d!l$m%Z%d d"l$m&Z&d d#l$m'Z'd d$l$m(Z(	%dCdDd.d/�Z)dEd7d8�Z*dFd;d<�Z+dGd>d?�Z,dHd@dA�Z-dBS)I�)�annotations)�List)�Optional)�Union)�AssignmentStmt)�CallExpr)�ClassDef)�	Decorator)�
LambdaExpr)�ListExpr)�
MemberExpr)�NameExpr)�PlaceholderNode)�RefExpr)�StrExpr)�
SymbolNode)�SymbolTableNode)�TempNode)�TypeInfo)�Var)�SemanticAnalyzerPluginInterface)�AnyType)�CallableType)�get_proper_type)�Instance)�NoneType)�
ProperType)�Type)�	TypeOfAny)�UnboundType)�	UnionType�)�apply)�infer)�names)�utilF�clsr�apir�
is_mixin_scan�bool�return�(Optional[List[util.SQLAlchemyAttribute]]cCst�||�}|durdS|j�d�rdSt�||�}t�|�|dur.|s,t�|||�|Sg}|jj	sG|j
��D]\}}t|||||�q9n#t�
|jj	�D]}t|t�r]t||||�qNt|t�rit||||�qNt||�|sxt�|||�t�||�|S)N�builtins)r%�info_for_cls�fullname�
startswith�get_mapped_attributes�establish_as_sqlalchemyr"� re_apply_declarative_assignments�defs�bodyr$�items�_scan_symbol_table_entry�flatten_typechecking�
isinstancer�!_scan_declarative_assignment_stmtr	� _scan_declarative_decorator_stmt�_scan_for_mapped_bases�add_additional_orm_attributes�set_mapped_attributes)r&r'r(�info�mapped_attributes�sym_name�sym�stmt�rC�I/usr/local/lib/python3.10/dist-packages/sqlalchemy/ext/mypy/decl_class.py�,scan_declarative_assignments_and_apply_types0sD
�

��
�
��
rE�name�str�valuer�
attributes�List[util.SQLAlchemyAttribute]�Nonec	Cs|t|j�}t|t�sdSd}t�|j�}d}|tjtjtjtj	tj
tjhvr4|jr1t|jd�}nWd}nT|tj
ur�|js?d}nIt|jd�}	t|	t�rN|	j}	t|	ttf�r�|�|	j|	�}
|
dur�t|
jt�r�t�|
jtj�r|tt�||
jg�t�g�}nt�|d�|
jj�|�|r�d}t�||�||j�|�ttj�}|dur�|jdus�J�|� tj!||jj"|jj#||j$d��dSdS)zaExtract mapping information from a SymbolTableNode that's in the
    type.names dictionary.

    NFrT�4Column type should be a TypeEngine subclass not '{}'z�Can't infer type from attribute {} on class {}. please specify a return type from this function that is one of: Mapped[<python type>], relationship[<target class>], Column[<TypeEngine>], MapperProperty[<python type>]�rF�line�column�typr>)%r�typer8rr$�type_id_for_named_node�MAPPED�RELATIONSHIP�COMPOSITE_PROPERTY�MAPPER_PROPERTY�SYNONYM_PROPERTY�COLUMN_PROPERTY�args�COLUMNrr�lookup_qualifiedrF�node�has_base_type_id�
TYPEENGINEr r#�#extract_python_type_from_typeenginerr%�fail�formatr.rr�special_form�append�SQLAlchemyAttributerNrOr>)r&r'rFrHrI�
value_type�left_hand_explicit_type�type_id�err�typeengine_argrA�msgrCrCrDr6rsv

�
�
���	
��
���r6rBr	c	Cs`|jD]}t|tttf�rt�|�tjurnqdS|jj	�
|�}d}t�|j
�rMttj�}t|jj
�}|j|_t|gt|��}	|jj|	_|	|jj	|<dSt|jjt�r�|jjj}
t|
t�rft�|
||�}ndS|tjtjtjtjtjtj hvr�|
j!r�t"|
j!d�}nE|tj#ur�|
j!r�|
j!d}t|t�r�|�$|j
|�}
|
dur�t|
jt%�r�t�&|
jtj'�r�t(t)�*||
jg�t+�g�}nt�,|d�-|
jj.�|
�|dur�d}t�,||�-|jj
�|�ttj�}t|jj
�}|j|_t|t�r�t"t�/||��}|�0tj1|g�|j_t�2t3|jj4|jj	��}t|g|�}	|jj|	_|�5tj6|j
|j7|j8||j9d��|	|jj	|<dS)a�Extract mapping information from a @declared_attr in a declarative
    class.

    E.g.::

        @reg.mapped
        class MyClass:
            # ...

            @declared_attr
            def updated_at(cls) -> Column[DateTime]:
                return Column(DateTime)

    Will resolve in mypy as::

        @reg.mapped
        class MyClass:
            # ...

            updated_at: Mapped[Optional[datetime.datetime]]

    NrrLz�Can't infer type from @declared_attr on function '{}';  please specify a return type from this function that is one of: Mapped[<python type>], relationship[<target class>], Column[<TypeEngine>], MapperProperty[<python type>]rM):�
decoratorsr8r
rrr$rR�
DECLARED_ATTRr3r4�indexr%�name_is_dunderrFrrrb�varr\rrrQ�funcr�ret_typer�type_id_for_unbound_typerSrTrUrVrWrXrYrrZr[rr]r^r r#r_rr`rar.�unbound_to_instance�
named_type�NAMED_TYPE_SQLA_MAPPED�expr_to_mapped_constructorr
�	argumentsrcrdrNrOr>)r&r'rBrI�dec�	dec_indexrf�any_�	left_node�new_stmt�	func_typergrirArj�rvaluerCrCrDr:�s�
��



��	�

���	
��


���
��	r:rc
	Csp|jd}t|t�sdS|jj�|j�}|dusJ�|j}t|t�r$dS||jus+J�t|t	�s2J�|jdkrG|�
|j�durEt�
|j�dS|jdkrSt�|j�n1|j�d�r[dS|jdkr�t|jt�snt�|d|�n|jjD]}t|ttf�r�t�||||�qrd}d}	|js�|jdur�t|jt�r�|j}	|jjd	kr�|�d	|�}
|
dur�|
jdur�t�|
j�tjur�t|jjd�}	|j}n!t|j�}t|t�r�t�|j�tjur�t|jd�}	|}n|}	d}t|jt�r�|dur�|	}n$t|jt ��rt|jj!t"��rt#�$||||	|jj!�}|du�rdSndS|du�sJ�|�%tj&|j|j'|j(||jd
��t�)||||	|�dS)zZExtract mapping information from an assignment statement in a
    declarative class.

    rN�__abstract__T�
__tablename__�__�_mypy_mapped_attrsz+_mypy_mapped_attrs is expected to be a list�MappedrM)*�lvaluesr8r
r>r$�getrFr\rr�
parse_boolr~r%�set_is_base�
set_has_tabler/rr`r5rr"�apply_mypy_mapped_attr�is_inferredrQrr[rRrSrrYrrr�calleerr#�#infer_type_from_right_hand_nameexprrcrdrNrO�apply_type_to_mapped_statement)
r&r'rBrI�lvaluerAr\�item�left_hand_mapped_typerf�
mapped_sym�	node_type�python_type_for_typerCrCrDr9gs�






�

�
��
���
���
�r9cCsNt�||�}|durdS|jdd�D]}|j�d�rqt|j|dd�qdS)z�Given a class, iterate through its superclass hierarchy to find
    all other classes that are considered as ORM-significant.

    Locates non-mapped mixins and scans them for mapped attributes to be
    applied to subclasses.

    Nr!���r,T)r()r%r-�mror.r/rE�defn)r&r'r>�	base_inforCrCrDr;�s��r;N)F)r&rr'rr(r)r*r+)r&rr'rrFrGrHrrIrJr*rK)
r&rr'rrBr	rIrJr*rK)
r&rr'rrBrrIrJr*rK)r&rr'rr*rK).�
__future__r�typingrrr�
mypy.nodesrrrr	r
rrr
rrrrrrrr�mypy.pluginr�
mypy.typesrrrrrrrrrr �r"r#r$r%rEr6r:r9r;rCrCrCrD�<module>sV�
B
Y