
    [h_)                       d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! ddl"m#Z# ddl"m$Z$ dd l%m&Z& dd!l%m'Z' d<d,Z(d=d-Z)d>d5Z*d=d6Z+d?d:Z,d;S )@    )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           	        t          |t                    r|j        }nt          |t                    r|j        }nd S | j        j        D ]O}t          |t                    r8t          |j        d         t                    r|j        d         j        |k    r nPt          j
        |d| |            d S |j        t          j
        |d|           d S t          |j                  }t          |t          t          t          f          sJ |                    t          j        ||j        |j        || j                             t+          |||j        d         |d            d S )Nr   zCan'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typer   r   r   r   appendSQLAlchemyAttributer.   r/   r1   apply_type_to_mapped_statement)r$   r%   r&   r(   r-   stmtleft_hand_explicit_types          h/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/ext/mypy/apply.pyapply_mypy_mapped_attrr?   -   s    $!! y	D'	"	" zt 	 	t^,,	4<?H55	 Q$,,E	#<d<<cBBBty	!		
 	
 	
 t-di88(I{!C      ;'	
 	
 	
   #T4<?$;T        c           	        d |D             }d}| j         j        D ]}t          |t                    rt          |j        d         t
                    rf|j        d         j        |v rQt          |j        d         j        t                    r+|j        d         j        }||j        d         j                 j	        }t          |j	                  }t          |t                    ryt          |t                    sct          |j        t                    rHt          |j        j        t                    r(t          |j        j        j        t
                    r|j        j        j        j        |j        j        j        j        j        t$          k    r|j        j        j        dk    rt          |j        j        d         t                    rt          |j        j        d         j        t(                    ret+          j        |||||j        j        d         j                  }	|	6t          |	t                    s!|	}|||j        d         j                 _	        d}t          |j	        t.                    r|j	        j	        j        t$          k    r%|J |                    t$          |g          |_	        |rt3          j        | j        |           dS dS )zlFor multiple class passes, re-apply our left-hand side types as mypy
    seems to reset them in place.

    c                    i | ]
}|j         |S  )r-   .0attrs     r>   
<dictcomp>z4re_apply_declarative_assignments.<locals>.<dictcomp>k   s    AAAd$)TAAAr@   Fr   N_empty_constructorT)r4   r5   r2   r	   r6   r   r-   noder   r8   r   r   rvaluer
   calleer   exprfullnamer#   argsr   r    #infer_type_from_right_hand_nameexprr   
named_typer!   set_mapped_attributesr1   )
r$   r%   r(   mapped_attr_lookupupdate_cls_metadatar<   	left_nodepython_type_for_typeleft_node_proper_typenew_python_type_for_types
             r>    re_apply_declarative_assignmentsrX   b   s    BAjAAA C C t^,,>	4<?H55>	 Q$(:::4<?/55 ; Q,I#5Q$$ ! %4IN$C$C! /==$/"#8+FF$/ t{H55	$/
 #4;#5zBB$/ #4;#5#:HEE$/ */4@*/4=-. .*/3GGG"4;#3A#6AA H"4;#3A#6#=wGG H =!-(+2  ) ,7
,kA A7 ,D(
 - 't|A';<A +/' y~x88>&/3III+777!$*-A,B" "	  9"38Z888889 9r@   r<   r	   lvaluer   r=   Optional[ProperType]rU   c                z   |j         }t          |t                    sJ |)d|_        |                     t
          |g          |_        nDd|_        |                     t
          |t          t          j	                  gn|g          |_        t          |j                  |_        |j        |||_        dS dS dS )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)rI   r2   r   is_inferred_defrP   r#   r8   r   r   special_formr"   rJ   )r%   r<   rY   r=   rU   rT   s         r>   r;   r;      s    : Ii%%%%% *!&"%<$=
 
	 "'" (/ /0011*+
 
	* -T[99DKy!5!A(			 !A!Ar@   c           
        t          j        | |          }|dS t          j        |          }d|j        vr|sd |D             }|j        dd         D ]I}d|j        vrt          j        ||          }|$|D ]"}|                    |j        |j	                   #Jg }	|
                                D ]f\  }
}|t          t          j                  }|	                    t          t!          |
|          |t#          |          t$                               gt'          || d|	t)                                 d|j        vr&t          j        |          rt-          || d	d           |st-          || d
d           dS dS )zCApply __init__, __table__ and other attributes to the mapped class.N__init__c                (    i | ]}|j         |j        S rC   )r-   r8   rD   s     r>   rG   z1add_additional_orm_attributes.<locals>.<dictcomp>  s    IIIdTY	IIIr@   r   
sqlalchemy)variabletype_annotationinitializerkind	__table__zsqlalchemy.sql.schema.Tablezsqlalchemy.orm.mapper.Mapper
__mapper__)r!   info_for_clsget_is_basenamesmrometadataget_mapped_attributes
setdefaultr-   r8   itemsr   r   r]   r9   r   r   r   r   r   r   get_has_table _apply_placeholder_attr_to_class)r$   r%   r(   r1   is_basemapped_attr_namesbasebase_cls_attributesrF   	argumentsr-   r0   s               r>   add_additional_orm_attributesrx      s    S#&&D|t$$G##G#IIjIIIHQrTN 		C 		CD4=00"&"<T3"G"G"*+ C C!,,TY	BBBBC 	*0022 
	 
	ID#{i455 s^^$' (&	      	Cj)WYYGGG$*$$);D)A)A$(3[	
 	
 	
  
(4l	
 	
 	
 	
 	

 
r@   qualified_namestrattrnamec                v   |                      |          }|r2t          |j        t                    sJ t	          |j        g           }nt          t          j                  }t          |          }|j	        dz   |z   |_
        |j        |_        ||_        t          t          |          |j        j        |<   d S )N.)lookup_fully_qualified_or_noner2   rI   r   r   r   r   r]   r   rM   	_fullnamer1   r8   r   r   rk   )r%   r$   ry   r{   symtype_vars          r>   rr   rr   4  s     
,
,^
<
<C
 0#(H-----$SXr22	.//
h--CL3&1CMxCHCH.tS99CHN8r@   N)
r$   r   r%   r   r&   r'   r(   r)   r*   r+   )r$   r   r%   r   r(   r)   r*   r+   )r%   r   r<   r	   rY   r   r=   rZ   rU   rZ   r*   r+   )
r%   r   r$   r   ry   rz   r{   rz   r*   r+   )-
__future__r   typingr   r   r   
mypy.nodesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   mypy.pluginr   mypy.plugins.commonr   
mypy.typesr   r   r   r   r   r   r   r    r    r!   rk   r"   r#   r?   rX   r;   rx   rr   rC   r@   r>   <module>r      s   # " " " " "                   $ $ $ $ $ $       % % % % % %                   ! ! ! ! ! !                   & & & & & &                   7 7 7 7 7 7 3 3 3 3 3 3       & & & & & &             ! ! ! ! ! !             " " " " " "                         - - - - - - ) ) ) ) ) )2 2 2 2jR9 R9 R9 R9jE) E) E) E)P2
 2
 2
 2
j: : : : : :r@   