
    ,hK                       S SK Jr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  SSK J!r!  SSK J"r"              S(S jr#          S)S jr$          S)S jr%            S(S  jr&          S)S! jr' S*           S+S# jjr(  S,             S-S$ jjr)          S.S% jr*        S/S& jr+        S0S' jr,g")1    )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)utilc                   [         R                  " U5      nUc  g U[         R                  L a  [        XX#U5      nU$ U[         R                  L a  [        XX#5      nU$ U[         R                  L a  [        XX#5      nU$ U[         R                  L a  [        XX#5      nU$ U[         R                  L a  [        XU5      nU$ U[         R                  L a  [        XX#5      nU$ g 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)apistmtnodeleft_hand_explicit_typeinfer_from_right_sidetype_idpython_type_for_types          Q/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/ext/mypy/infer.py#infer_type_from_right_hand_nameexprr6   (   s    &&'<=G	ELL	 6t6K 
4  / 
ELL	 ;t 
,  ' 
E&&	&<t 
$   
E))	)Dt 
   
E**	*B. 
   
E,,	,Gt 
       c                N   [        UR                  [        5      (       d   eUR                  R                  S   nSn[        U[        5      (       a7  [        UR
                  [        5      (       a  UR
                  n[        U/ 5      n[        R                  " UR                  S5      n[        R                  " UR                  S5      nSn	Ub?  U R                  U5      SL a+  Uc(  Sn	Ub!  U R                  [        R                  U/5      nGO5Ub  U R                  U5      SL Ga  UGb  Sn	[        U[        5      (       a  UR                  n[        U[        5      (       a;  [        UR
                  [        5      (       a  Ub  [        UR
                  U/5      nGO[        U[        5      (       a  [        UR
                  [        5      (       a  UR
                  R                   b  Ub  [        UR
                  R                   ["        5      (       a  [%        UR
                  R                   R&                  5      n
[        U
["        5      (       aA  [%        U
R&                  5      n[        U[        5      (       a  [        UR                   U/5      nO[        R(                  " U SUR                  5        SnOUbR  U R                  U5      SL a>  Ub"  [        R(                  " U SUR                  5        Ub  [+        U[-        5       /5      nO5Uc2  S	n[        R(                  " XR/                  UR0                  5      U5        Uc  [3        XU5      $ UbO  U	(       a:  [        U[        5      (       d   e[        U[        5      (       d   e[5        XX55      $ [7        U UUU5      $ U$ )
ar  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 sensezCan'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   r0   r   r   r   get_callexpr_kwarg
parse_bool
named_typer   NAMED_TYPE_BUILTINS_LISTcalleer
   typer   r   ret_typefailr   r   formatnamer+   3_infer_collection_type_from_left_and_inferred_right(_infer_type_from_left_and_inferred_right)r.   r/   r0   r1   target_cls_argr4   related_object_typeuselist_argcollection_cls_argtype_is_a_collectionrtcallable_ret_typemsgs                r5   r'   r'   P   sg   < dkk8,,,,[[%%a(N15.(++
X1 1 -11'(;R@  ))$++yAK/3/F/F'0 ! 	NN;'4/&#+#&>>..1E0F$  	s~~k:dB

(#((33!3!:!:((33
##X9
 9
 $/ (0&++.B-C($ )844-22G<<"'',,8#/
 055::LII();)@)@)E)E)N)NOB!"l33,;BKK,H)%&7BB3; 1 6 6!5 640
 II-	 $( 		 S^^K%@E%I)II&	  +#,%xz2$ 
 #*9  IIc::dii0$7#2.
 	
 
!	,5x@@@@2H====F2  <'$	  $#r7   c                X   [        UR                  [        5      (       d   eUR                  R                  S   nSn[        U[        5      (       a8  [        UR
                  [        5      (       a  UR
                  n[        U/ 5      nOSnUc  [        XU5      $ Ub  [        XX55      $ U$ )z+Infer the type of mapping from a Composite.r   N)
r;   r<   r   r=   r   r0   r   r   r+   rI   )r.   r/   r0   r1   rJ   r4   rK   s          r5   r-   r-      s     dkk8,,,,[[%%a(N.(++
X1 1 -11'(;R@##2.
 	
 
!	,7.
 	
 $#r7   c                    [        UR                  [        5      (       d   e[        R                  " U5      n[        XU5      $ )zNInfer the type of mapping from a right side expression
that returns Mapped.


)r;   r<   r   r   type_for_calleer+   )r.   r/   r0   r1   r2   the_mapped_types         r5   r#   r#     sA     dkk8,,,, **+@AO.* r7   c                B   [        UR                  [        5      (       d   eUR                  R                  (       an  UR                  R                  S   n[        U[        5      (       a@  [        R
                  " UR                  5      nU[        R                  L a  [        U UUUUS9$ [        UR                  [        5      (       aK  [        R
                  " UR                  R                  5      nU[        R                  L a  [        U UUU5      $ [        XU5      $ )zInfer the type of mapping from a ColumnProperty.

This includes mappings against ``column_property()`` as well as the
``deferred()`` function.

r   )right_hand_expression)r;   r<   r   r=   r   r!   rB   r$   r%   QUERY_EXPRESSIONr+   )r.   r/   r0   r1   first_prop_argr3   s         r5   r)   r)   6  s     dkk8,,,,{{))!,nh//..~/D/DEG %,,&3+*8  $++x((**4;;+=+=> e,,,/'	  /* r7   Nc                   [        U[        5      (       d   eSnUc,  [        UR                  [        5      (       d  gUR                  nUR                  SS  H  n[        U[        5      (       a;  [        UR
                  [        5      (       a  UR
                  nUR                  n  OxMS  [        U[        [        45      (       a'  [        UR                  [        5      (       a  UnSn  O6M  [        U[        45      (       a  M  [        U[        45      (       a  M   e   Uc  g[        UR                  [        5      (       ax  [        R                  " UR                  R                  [        R                   5      (       a:  [#        XR                  W5      nUb  [%        XX85      $ ['        U[)        5       /5      $ [+        XU5      $ )a  Infer the type of mapping from a Column.

E.g.::

    @reg.mapped
    class MyClass:
        # ...

        a = Column(Integer)

        b = Column("b", String)

        c: Mapped[int] = Column(Integer)

        d: bool = Column(Boolean)

Will resolve in MyPy as::

    @reg.mapped
    class MyClass:
        # ...

        a: Mapped[int]

        b: Mapped[str]

        c: Mapped[int]

        d: Mapped[bool]

Nr       )r;   r   r<   r   r=   rB   r   r   r   r0   r   r   r   r   
mro_has_idmro
TYPEENGINE#extract_python_type_from_typeenginerI   r   r   r+   )	r.   r/   r0   r1   rW   rB   
column_arg	type_argsr4   s	            r5   r%   r%   g  s   L dC    F$$++x00 $+0015
j(++*++W55#**2<//		 6
 
Xz$:;;*//844#	 
WJ//
ZM22 51 64 ~&++x((U-=-=)). .  Ci 
 #.;2 
 2HJ?@@ 3.
 	
r7   c                ^   Uc  UnUc  Un[        X#5      (       d  U R                  [        R                  U/5      nSn[        R
                  " U UR                  UR                  [        R                  " X@R                  5      [        R                  " X`R                  5      5      U5        U$ )zValidate type when a left hand annotation is present and we also
could infer the right hand side::

    attrname: SomeType = Column(SomeDBType)

zRLeft hand assignment '{}: {}' not compatible with ORM mapped expression of type {})
r   r@   r   NAMED_TYPE_SQLA_MAPPEDr   rE   rF   rG   format_typeoptions)r.   r0   r1   r4   orig_left_hand_typeorig_python_type_for_typeeffective_typerQ   s           r5   rI   rI     s     "5 ($8!-DD((+D*E

4 	 			JJ		  !4kkB  =
 	
 r7   c           	     &   UnUnUR                   (       a1  [        UR                   S   5      n[        UR                   S   5      nOUnUn[        U[        [        45      (       d   e[        U[        [        45      (       d   e[        U UUUUUS9$ )Nr   )rg   rh   )r=   r   r;   r   r   rI   )r.   r0   r1   r4   rg   rh   left_hand_argpython_type_args           r5   rH   rH     s     2 4##'(?(D(DQ(GH)*>*C*CA*FG/.mh	%:;;;;o)'<====3/"; r7   c                    Ucj  Sn[         R                  " XR                  UR                  5      U5        U R	                  [
        R                  [        [        R                  5      /5      $ U$ )zDetermine the type based on explicit annotation only.

if no annotation were present, note that we need one there to know
the type.

zCan't infer type from ORM mapped expression assigned to attribute '{}'; please specify a Python type or Mapped[<python type>] on the left hand side.)
r   rE   rF   rG   r@   r   rd   r   r   special_form)r.   r0   r1   rQ   s       r5   r+   r+     sc     &; 	 			#zz$)),d3~~((793I3I+J*K
 	
 '&r7   c                   UR                   S:X  a  U(       a  US   n[        U[        5      (       ae  [        UR                  [        5      (       aF  UR                  R
                   H+  nUR                   S:X  d  M  [        UR                  / 5      s  $    O U R                  [        R                  / 5      $ UR                  S5      (       d
   SU-  5       eU R                  S5      nUb  [        UR                  [        5      (       d   e[        [        U/ 5      UR                  5      n[        UR                  S   5      $ )Nzsqlalchemy.sql.sqltypes.Enumr   z	enum.Enumz"sqlalchemy.sql.type_api.TypeEnginez+could not extract Python type from node: %s)fullnamer;   r   r0   r   r^   r   r@   r   NAMED_TYPE_BUILTINS_STRhas_baselookup_fully_qualified_or_noner   r   r=   )r.   r0   rb   	first_argbase_type_engine_symtype_engines          r5   r`   r`   .  s$   
 }}669aL	i))jNNH/
 /
 #++>>[0#INNB77 ,
 >>%"?"?DD===>> 5<> 88,O &:h, ,   ,rK ;++B/00r7   )r.   r   r/   r   r0   r   r1   Optional[ProperType]r2   r   returnry   )
r.   r   r/   r   r0   r   r1   ry   rz   ry   r    )r.   r   r/   r   r0   r   r1   ry   rW   zOptional[CallExpr]rz   ry   )NN)r.   r   r0   r   r1   r   r4   r   rg   ry   rh   ry   rz   ry   )
r.   r   r0   r   r1   r   r4   r   rz   ry   )r.   r   r0   r   r1   ry   rz   ry   )r.   r   r0   r   rb   zSequence[Expression]rz   r   )-
__future__r   typingr   r   mypy.maptyper   
mypy.nodesr   r   r	   r
   r   r   r   r   r   r   r   mypy.pluginr   mypy.subtypesr   
mypy.typesr   r   r   r   r   r   r   r    r   r   r6   r'   r-   r#   r)   r%   rI   rH   r+   r`   r\   r7   r5   <module>r      s   #   2 %  !  ! !      7 $  # &   !      % 	(% 
%  %  2	% 
 #%  % Pc$	(c$
c$ c$ 2	c$
 c$L$	($
$ $ 2	$
 $@	(
  2	
 # @.	(.
. . 2	.
 .l 15`
	(`

`
 `
 2	`

 .`
 `
P 156:'	('
' (' %	'
 .'  4' 'T	(
 & #	
 :'	('
' 2' 	': 1	( 1
 1 $ 1 	 1r7   