
    [hC                       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"l$m&Z& d d#l$m'Z' d d$l$m(Z( 	 d>d?d.Z)d@d6Z*dAd9Z+dBd;Z,dCd<Z-d=S )D    )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]]c                   t          j        | |          }|d S | j                            d          rd S t          j        ||          }t          j        |           ||st          j        | ||           |S g }| j        j	        s3|j
                                        D ]\  }}t          | ||||           npt          j        | j        j	                  D ]Q}t          |t                    rt!          | |||           *t          |t"                    rt%          | |||           Rt'          | |           |st          j        | ||           t          j        ||           |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stmts           m/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/ext/mypy/decl_class.py,scan_declarative_assignments_and_apply_typesrF   0   s   
 S#&&D|t		 	 	,	, t 	"4-- 
 	 &&&$
  	P 23=NOOO  8=  "Z--// 	 	MHc$S(C):   	
 -chm<< 	 	D$// 1d$5    D),, 0d$5   3$$$ I+C6GHHHt%6777    namestrvaluer   
attributesList[util.SQLAlchemyAttribute]Nonec           	        t          |j                  }t          |t                    sdS d}t	          j        |j                  }d}|t          j        t          j        t          j        t          j	        t          j
        t          j        hv r'|j        rt          |j        d                   }n5d}n1|t          j        u r"|j        sd}nt          |j        d                   }	t          |	t                    r|	j        }	t          |	t          t          f          r|                    |	j        |	          }
|
t          |
j        t                    rt	          j        |
j        t          j                  r7t+          t-          j        ||
j        g           t1                      g          }n3t3          j        |d                    |
j        j                  |           |rJd}t3          j        ||                    || j                  |            t;          t<          j                  }|P|j        J |                     t3          j!        ||j        j"        |j        j#        || j$                             dS dS )zaExtract mapping information from a SymbolTableNode that's in the
    type.names dictionary.

    NFr   T4Column type should be a TypeEngine subclass not '{}'zCan'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>]rH   linecolumntypr@   )%r   typer:   r   r%   type_id_for_named_nodeMAPPEDRELATIONSHIPCOMPOSITE_PROPERTYMAPPER_PROPERTYSYNONYM_PROPERTYCOLUMN_PROPERTYargsCOLUMNr    r   lookup_qualifiedrH   nodehas_base_type_id
TYPEENGINEr!   r$   #extract_python_type_from_typeenginer   r&   failformatr0   r   r   special_formappendSQLAlchemyAttributerQ   rR   r@   )r'   r(   rH   rJ   rK   
value_typeleft_hand_explicit_typetype_iderrtypeengine_argrC   msgs               rE   r8   r8   r   s    !,,Jj(++ "*:?;;G C     ? 	&5joa6H&I&I##CC	EL	 	  	CC:I"; ;N .(33 5!/!4.;*ABB **>+>OO?z#(H'E'E?-ch8HII 2; % I$'2!" !" !)

	3 3// 	006sx7H0I0I&	    	BB 	 		#szz$113777"))*@"A"A*z%%%$Z_z(+X  	
 	
 	
 	
 	
 +*rG   rD   r
   c           	        |j         D ]F}t          |t          t          t          f          r"t          j        |          t
          j        u r nGdS | j        j	        
                    |          }d}t          j        |j                  r~t          t          j                  }t          |j        j                  }|j        |_        t'          |gt)          |                    }	|j        j        |	_        |	| j        j	        |<   dS t          |j        j        t.                    r|j        j        j        }
t          |
t2                    rt          j        |
| |          }ndS |t
          j        t
          j        t
          j        t
          j        t
          j        t
          j         hv r"|
j!        rtE          |
j!        d                   }n|t
          j#        u r|
j!        r|
j!        d         }t          |t2                    r|$                    |j        |          }|t          |j        tJ                    rt          j&        |j        t
          j'                  r7tQ          tS          j*        ||j        g           tW                      g          }n3t          j,        |d-                    |j        j.                  |
           |Nd}t          j,        ||-                    |j        j                  |           t          t          j                  }t          |j        j                  }|j        |_        t          |t2                    r"tE          t          j/        ||                    }|0                    t
          j1        |g          |j        _        t          j2        tg          |j        j4        |j        j	                            }t'          |g|          }	|j        j        |	_        |5                    t          j6        |j        |j7        |j8        || j9                             |	| j        j	        |<   dS )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]]

    Nr   rO   zCan'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>]rP   ):
decoratorsr:   r   r   r   r%   rU   DECLARED_ATTRr5   r6   indexr&   name_is_dunderrH   r   r   re   varr_   r   r   rT   funcr   ret_typer    type_id_for_unbound_typerV   rW   rX   rY   rZ   r[   r\   r   r]   r^   r   r`   ra   r!   r$   rb   r   rc   rd   r0   unbound_to_instance
named_typeNAMED_TYPE_SQLA_MAPPEDexpr_to_mapped_constructorr   	argumentsrf   rg   rQ   rR   r@   )r'   r(   rD   rK   dec	dec_indexri   any_	left_nodenew_stmt	func_typerj   rl   rC   rm   rvalues                   rE   r<   r<      s   8   sXz:>??	,S11U5HHHE##D))I4849%% 7 y-..TX]++		!9+x~~>>!+#+i 	DINL	1	1 *IN+	i-- 	4YSIIGG F "(%&%   '6inQ6G&H&H##$$$&^A.N.+66 **>+>OO?z#(H'E'E?-ch8HII 2; % I$'2!" !" !)

	3 3// 	006sx7H0I0I%	   &
B 	 		#szz$(-00$777"))*@"A"A''IXIN );77 
"1$S*ABB#
 #
 ..$'>&? IN -49&	77 F yk622HN'HM ;'	
 	
 	
    (CHM)rG   r   c           	        |j         d         }t          |t                    sdS | j        j                            |j                  }|J |j        }t          |t                    rdS ||j        u sJ t          |t                    sJ |j        dk    r7|
                    |j                  du rt          j        | j                   dS |j        dk    rt          j        | j                   n|j                            d          rdS |j        dk    rst          |j        t                     st          j        |d|           nB|j        j        D ]5}t          |t          t&          f          rt)          j        | |||           6d}d}	|j        s|j        t          |j        t0                    r|j        }	|j        j        d	k    rj|                    d	|           }
|
R|
j        Kt	          j        |
j                  t          j        u r&t9          |j        j        d                   }	|j        }not9          |j                  }t          |t<                    rBt	          j        |j                  t          j        u rt9          |j        d                   }	|}n|}	d}t          |j        t>                    r||	}nbt          |j        t@                    rFt          |j        j!        tD                    r'tG          j$        ||||	|j        j!                  }|dS ndS |J |%                    t          j&        |j        |j'        |j(        || j        
                     t)          j)        ||||	|           dS )zZExtract mapping information from an assignment statement in a
    declarative class.

    r   N__abstract__T__tablename_____mypy_mapped_attrsz+_mypy_mapped_attrs is expected to be a listMappedrP   )*lvaluesr:   r   r@   r%   getrH   r_   r   r   
parse_boolr   r&   set_is_baseset_has_tabler1   r   rc   r7   r   r#   apply_mypy_mapped_attris_inferredrT   r    r^   rU   rV   r   r\   r   r   r   calleer   r$   #infer_type_from_right_hand_nameexprrf   rg   rQ   rR   apply_type_to_mapped_statement)r'   r(   rD   rK   lvaluerC   r_   itemleft_hand_mapped_typeri   
mapped_sym	node_typepython_type_for_types                rE   r;   r;   g  s    \!_Ffh'' 
(.

V[
)
)C
 ???8D$(( 6;dC     yN"">>$+&&$..SX&&&	o	%	%38$$$$			d	#	# M	*	*	*$+x00 	MIcH$OOOO) M MdXw$788 M0c4LLL,048 ))49,di-- 	6 '+i#y~)) 11(C@@
*"34Z_EE|$ $ />	q)/ /+ -1I) $DI..	y(++	),Y^<<LL '6inQ6G&H&H#$-!! '0#$(!$+x(( -B-N
  7	DK	*	* zG0 0   %Ht4dk6H 
  
  'F ( 	+++ ;$	
 	
 	
   
(    rG   c                    t          j        | |          }|dS |j        dd         D ]4}|j                            d          rt          |j        |d           5dS )zGiven 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/   mror0   r1   rF   defn)r'   r(   r@   	base_infos       rE   r=   r=     s     S#&&D|Xad^ 	
 	
	((44 	
 	5NCt	
 	
 	
 	
 	
	
 	
rG   N)F)r'   r	   r(   r   r)   r*   r+   r,   )r'   r	   r(   r   rH   rI   rJ   r   rK   rL   r+   rM   )
r'   r	   r(   r   rD   r
   rK   rL   r+   rM   )
r'   r	   r(   r   rD   r   rK   rL   r+   rM   )r'   r	   r(   r   r+   rM   ).
__future__r   typingr   r   r   
mypy.nodesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   mypy.pluginr   
mypy.typesr   r   r   r   r   r   r   r   r    r!    r#   r$   r%   r&   rF   r8   r<   r;   r=    rG   rE   <module>r      s   # " " " " "                   % % % % % %                         ! ! ! ! ! !       ! ! ! ! ! !       & & & & & &             ! ! ! ! ! ! & & & & & &                   7 7 7 7 7 7       # # # # # # & & & & & &             ! ! ! ! ! !                   " " " " " "                                      ? ? ? ? ?DV
 V
 V
 V
rY( Y( Y( Y(x   D
 
 
 
 
 
rG   