
    %^g                    X   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ dd
l,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZM ddlNmOZO erddlPZddlmQZQ  G d d      ZRddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4dZS	 d5	 	 	 	 	 	 	 	 	 d6dZT	 d5	 	 	 	 	 	 	 	 	 d7dZU	 d5	 	 	 	 	 	 	 	 	 	 	 d8dZV	 	 	 	 	 	 	 	 	 	 d9dZWd:dZXd;dZY	 	 	 	 	 	 	 	 	 	 d<dZZd=dZ[d>dZ\	 	 	 	 	 	 	 	 	 	 d?dZ]d@dZ^dd 	 	 	 	 	 	 	 dAd!Z_dBd"Z`dd#	 	 	 	 	 	 	 	 	 	 	 	 	 dCd$Za	 dD	 	 	 	 	 	 	 	 	 	 	 dEd%ZbdFd&Zc G d' d(eO      ZddGd)Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 dHd*Zfddd+	 	 	 	 	 	 	 	 	 	 	 	 	 dId,Zg	 	 	 	 	 	 	 	 dJd-Zh	 	 	 	 	 	 	 	 dKd.Zi	 	 	 	 	 	 	 	 	 	 dLd/Zj	 d5	 	 	 	 	 	 	 	 	 	 	 	 	 dMd0ZkdNd1Zl	 	 	 	 	 	 	 	 	 	 	 	 	 	 dOd2ZmdPd3Zny)Qz!Type checking of attribute access    )annotations)TYPE_CHECKINGCallableSequencecast)meetmessage_registrysubtypes)erase_typevars)expand_self_typeexpand_type_by_instancefreshen_all_functions_type_vars)map_instance_to_supertype)MessageBuilder)ARG_POSARG_STAR	ARG_STAR2EXCLUDED_ENUM_ATTRIBUTESSYMBOL_FUNCBASE_TYPESContext	DecoratorFuncBaseFuncDef	IndexExprMypyFileNameExprOverloadedFuncDef
SymbolNodeSymbolTableTempNode	TypeAliasTypeInfoTypeVarExprVaris_final_node)AttributeContext)		bind_selfclass_callableerase_to_boundfunction_typeget_type_varsmake_simplified_unionsupported_self_typetuple_fallbacktype_object_type_from_function)AnyTypeCallableTypeDeletedTypeFunctionLikeInstanceLiteralTypeNoneType
OverloadedParamSpecTypePartialType
ProperType	TupleTypeTypeTypedDictType	TypeOfAnyTypeTypeTypeVarLikeTypeTypeVarTupleTypeTypeVarType	UnionTypeget_proper_type)TypeTraverserVisitorN)statec                      e Zd ZdZdddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
dZddZddZddddd	 	 	 	 	 	 	 	 	 dd	Zy)MemberContextzInformation and objects needed to type check attribute access.

    Look at the docstring of analyze_member_access for more information.
    NF)module_symbol_tableno_deferralis_selfc                   || _         || _        || _        || _        |xs || _        || _        || _        || _        |	| _        |
| _	        || _
        y N)	is_lvalueis_superis_operatororiginal_type	self_typecontextmsgchkrI   rJ   rK   )selfrN   rO   rP   rQ   rS   rT   rU   rR   rI   rJ   rK   s               0lib/python3.12/site-packages/mypy/checkmember.py__init__zMemberContext.__init__X   sZ     # &*"3m#6 &    c                8    | j                   j                  |      S rM   )rU   
named_type)rV   names     rW   r[   zMemberContext.named_types   s    xx""4((rY   c                <    | j                   j                  ||       y rM   )rU   handle_cannot_determine_type)rV   r\   rS   s      rW   not_ready_callbackz MemberContext.not_ready_callbackv   s    --dG<rY   )messagesrR   rN   rQ   c               @   t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  
      }|||_        |||_        |||_        |||_        |S )N)
rN   rO   rP   rQ   rS   rT   rU   rR   rI   rJ   )rH   rN   rO   rP   rQ   rS   rT   rU   rR   rI   rJ   )rV   r`   rR   rN   rQ   mxs         rW   copy_modifiedzMemberContext.copy_modifiedy   s     nn]]((,,LLnn $ 8 8((
 BF $BL $BL$,B	rY   )rN   boolrO   rd   rP   rd   rQ   r<   rS   r   rT   r   rU   mypy.checker.TypeCheckerrR   Type | NonerI   SymbolTable | NonerJ   rd   rK   rd   returnNone)r\   strrh   r4   )r\   rj   rS   r   rh   ri   )
r`   zMessageBuilder | NonerR   rf   rN   zbool | NonerQ   rf   rh   rH   )__name__
__module____qualname____doc__rX   r[   r_   rc    rY   rW   rH   rH   R   s      37!  	
     &  0   
6)= +/!%!%%) ( 	
  # 
rY   rH   F)override_infoin_literal_contextrR   rI   rJ   rK   c                   t        |||||||||||      }t        | |||	      }t        |      }|
r(t        |t              r|j
                  |j
                  S |S )a  Return the type of attribute 'name' of 'typ'.

    The actual implementation is in '_analyze_member_access' and this docstring
    also applies to it.

    This is a general operation that supports various different variations:

      1. lvalue or non-lvalue access (setter or getter access)
      2. supertype access when using super() (is_super == True and
         'override_info' should refer to the supertype)

    'original_type' is the most precise inferred or declared type of the base object
    that we have available. When looking for an attribute of 'typ', we may perform
    recursive calls targeting the fallback type, and 'typ' may become some supertype
    of 'original_type'. 'original_type' is always preserved as the 'typ' type used in
    the initial, non-recursive call. The 'self_type' is a component of 'original_type'
    to which generic self should be bound (a narrower type that has a fallback to instance).
    Currently this is used only for union types.

    'module_symbol_table' is passed to this function if 'typ' is actually a module
    and we want to keep track of the available attributes of the module (since they
    are not available via the type object directly)
    )rN   rO   rP   rQ   rS   rT   rU   rR   rI   rJ   rK   )rH   _analyze_member_accessrD   
isinstancer4   last_known_value)r\   typrS   rN   rO   rP   rT   rQ   rU   rp   rq   rR   rI   rJ   rK   rb   resultpossible_literals                     rW   analyze_member_accessry      sx    R 
#/
B $D#r=AF&v.'2--9000rY   c                2   t        |      }t        |t              rt        | |||      S t        |t              rt	        t
        j                  |      S t        |t              rt        | ||      S t        |t              r|j                         rt        | ||      S t        |t              rt        | |||      S t        |t              rt        | t!        |      ||      S t        |t"        t        f      rt        | |j$                  ||      S t        |t&              rt)        | |||      S t        |t*              rt-        | ||      S t        |t.              rUt        |t0              r-|j2                  r!t        | t5        |j2                        ||      S t        | |j6                  ||      S t        |t8              r?|j:                  j=                  ||j>                         t	        t
        j@                        S tC        |jD                  || |      S )N)
source_any)#rD   rt   r4   analyze_instance_member_accessr0   r>   from_another_anyrC   analyze_union_member_accessr3   is_type_obj#analyze_type_callable_member_accessr?   analyze_type_type_member_accessr;   rs   r.   r5   fallbackr=   analyze_typeddict_accessr6   analyze_none_member_accessr@   rB   valuesr,   upper_boundr2   rT   deleted_as_rvaluerS   
from_errorreport_missing_attributerQ   )r\   rv   rb   rp   s       rW   rs   rs      s   
 #
C#x -dC]KK	C	!y11cBB	C	#*4b99	C	&3??+<24bAA	C	".tS"mLL	C	#%dN3,?]SS	C+|4	5%dCLL"mLL	C	''c2}EE	C	")$R88	C	)c;'CJJ)+CJJ7]  &dCOOROO	C	%
  bjj1y++,,#B$4$4c4DDrY   c                   |j                   j                  ry|j                   j                         5  |j                  j	                         5 }|j                   j                  ||      }|	 ddd       ddd       yt        | |||      }|j                          cddd       cddd       S # 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)z7Check if the given type has the attribute when awaited.FN)rU   checking_missing_awaitchecking_await_setrT   filter_errorsget_precise_awaitable_typers   has_new_errors)r\   rv   rb   rp   local_errorsaw_type_s          rW   may_be_awaitable_attributer     s     
vv$$		"	"	$bff&:&:&<&&33CF? '=	$	$ #4"mD..00 '=&<	$	$&<&<	$	$	$s/   C B/-C>B/	C/B8	4CCc                6   |j                   j                  | |||j                  |j                        }|j                   j	                         s4t        ||||      r&|j                   j                  |j                  |       t        t        j                        S rM   )
rT   has_no_attrrS   rI   prefer_simple_messagesr   possible_missing_awaitr0   r>   r   )rQ   rv   r\   rb   rp   
error_codes         rW   r   r     sq     ##M3bjj"J`J`aJ66((*%dC]CFF))"**jA9''((rY   c                   | dk(  rY|j                   sM|j                  j                  t        j                  |j
                         t        t        j                        S |j                  }|r|}t        j                  rw|j                  t        j                  d   k(  rW| t        j                  d   k(  rA|j                  j                   dj                  t        j                   |j
                         |j                  |       }|rnt!        |t"              s]|j                   rt%        ||       |j&                  rt!        |t(              sJ |j*                  d   }t!        |t"              sJ |j,                  rCt/        |j*                  x}      dkD  r)|j0                  j3                  |d   |j
                         t5        | |j6                  |||      S |j,                  r%|j                  j9                  |j
                         t!        |t(              st;        ||j=                  d            }n|j                  W|j>                  s2|j*                  r&|jA                  |j                  |j
                         t        t        jB                        S t!        |j                  tD              sJ |j                  }tG        |      }|jH                  sptK        jL                  |jN                  |      }	tQ        ||	|jR                  |j
                  | |j                        }tU        ||jV                  |jR                        }tY        ||jZ                        }t]        ||      }
t_        |
       |
S ta        | |||      S )NrX   r      zOccurrence of '{}.{}'builtins.functionis_classmethod)1rO   rT   failr	   CANNOT_ACCESS_INITrS   r0   r>   r   typerF   find_occurrencesr\   noteformat
get_methodrt   r   validate_super_callis_propertyr   itemsrN   lenrU   warn_deprecatedanalyze_varvarcant_assign_to_methodr*   r[   rJ   r_   special_formr7   r   	is_staticr   
meet_typesrQ   check_self_argis_classr'   rR   r   infor   freeze_all_type_varsanalyze_member_var_access)r\   rv   rb   rp   r   methodgetterr   	signaturedispatched_typemember_types              rW   r|   r|   "  s    z"++ 	$77Dy++,, 88D 	II//22E**1--
2+22E4J4JKRZZX __T"Fj3;;+f&7888\\!_Ffi000||fll%:U!;a!?&&uQx<tVZZdB??<<FF((4&"34%fbmm<O.PQI{{" ~~&,,))&++rzzBy5566fkk:666I3I>	 #oob.>.>DO&?FOORZZrvvI ")R\\&//ZI (V[[9-i=[) )sD"==rY   c                   d}t        | t              r| j                  rd}| }ndt        | t              rT| j                  rHt        | j                  t              r| j                  n| j                  j
                  }|j                  }|rF|j                  j                  | j                  | j                  j                  |j                         y y )NFT)rt   r   is_trivial_bodyr   implfuncrT   unsafe_superr\   r   rS   )noderb   r   r   s       rW   r   r   g  s    L$ T%9%9	D+	,99 *499g >499DIINND//L
DIItyy~~rzzB rY   c                   |j                   d   j                  }t        |t              sJ t        |t              rt        |      }t        |t              r|j                  }t        |t              rX|j                  s5t        || ||j                   d   j                  |j                        }|r|S t        | |j                  |      S J d|       )Nr   )original_varsmcs_fallbackzUnexpected type )r   ret_typert   r:   r;   r.   r=   r   r4   rP   analyze_class_attribute_access	variablesrs   )r\   rv   rb   r   rw   s        rW   r   r   t  s     yy|$$Hh
+++(I&!(+(M*$$(H%~~ 4$#))A,2H2HWZWcWcF %dCLL"==5(55urY   c                R   d }|j                  d      }t        |j                  t              r|j                  }n$t        |j                  t              r2|j
                  j                         5  t        | |||      cd d d        S t        |j                  t              rt        |j                  j                        }t        |t              r|}nt        |t              r8t        | t        j                  ||j                  |j                        ||      S t        |t               rt#        |      }n&t        |t              r|j
                  j                         5  t        | |||      cd d d        S t        |j                  t               rt#        |j                        }nt        |j                  t$              r1|j                  j'                         r|j                  j(                  }nht        |j                  t              rNt        |j                  j                  t              r*|j                  j                  j*                  j,                  }d}||j*                  j,                  xs |}|rQ|j.                  sEt1        || |||      }|r3t        t        |      t              r|j*                  j2                  s|S d}|j
                  j                  |      5  t        | |||      cd d d        S # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nbuiltins.type)linecolumnF)r   rp   T)r   )r[   rt   itemr4   r0   rT   r   rs   rB   rD   r   rC   r?   make_normalizedr   r   r;   r.   r3   r   r   r   metaclass_typerP   r   fallback_to_any)	r\   rv   rb   rp   r   r   r   ignore_messagesrw   s	            rW   r   r     sD    D}}_-H#((H%xx	CHHg	&VV!!#)$"mL $#	CHHk	*%chh&:&:;k8,DY/)((388CJJW	  Y/!+.DW-%%'-dHb-P ('	CHHi	(chh'	CHHl	+0D0D0Fxx  	CHHh	'chhmmX.88==%%44DO99++7xBNN/$
 v6@TYYE^E^ #'			O		<%dHb-H 
=	<W $#  ('6 
=	<s$   0L%L-LLLL&c           	        |j                   j                         5  g }|j                         D ]0  }|j                  |      }|j	                  t        | ||             2 	 d d d        t        |      S # 1 sw Y   t              S xY w)N)rR   )rT   disable_type_namesrelevant_itemsrc   appendrs   r,   )r\   rv   rb   resultssubtypeitem_mxs         rW   r~   r~     sx    		"	"	$))+G&&&9GNN1$IJ , 
% !)) 
% !))s   AA55Bc           	         | dk(  r;t        d|j                  d            }t        g g g ||j                  d            S t        | |j                  d      |      S )N__bool__Fzbuiltins.boolr   r   	arg_types	arg_kinds	arg_namesr   r   builtins.object)r5   r[   r1   rs   )r\   rv   rb   literal_falses       rW   r   r     s`    z#EBMM/4RS"]]#67
 	
 &dBMM:K,LbQQrY   c           
     R   t        || |j                        }|j                  j                  ||j                         |}t        |t              r.|j                  }|j                  rt        |j                  |       t        |t              r(t        | t        ||j                              }||_        t        |t               rP|j                  j"                  j%                  ||j                  |j                        }t        | |      }||_        t        |t              rh||    j&                  }|j                  r<|j                  j)                         s"t+        | ||j,                  |j                         t/        | |||||      S t        |t0              rJ d       t        |t2              rT|j                  j4                  j7                  |j8                         |j                  j"                  j;                  |      S |s| dvr|j<                  s|j>                  |j                  s'dD ]   }|jA                  |      }	|	s|	j                  j8                  dk7  s2tC        |	|||jD                  ||	      }
tG        ||	j                        }tI        tK        |
|            }t        |tL              r|jN                  }n|}|	j                  j8                   d
|  }|j                  jP                  jS                  |      }|rF |tU        tI        |jV                        ||j                  |j                  |j                              }|c S  n|jA                  d      }|r|j                  j8                  dk7  rtC        ||||jD                  | |jY                  d      	      }tG        ||j                        }tI        tK        ||            }t        |tL              r't[        |j\                        dkD  r|j\                  d   S |j^                  j`                  rtc        td        jf                        S |jh                  rG| |jh                  jj                  v r/|jh                  jl                  s|jh                  jj                  |    S |j                  r?|j,                  jo                  | |j                         tc        td        jp                        S ts        |jV                  || |      }|j>                  | |j>                  v r|j>                  |    jt                  sw|j>                  |    jv                  }ty        |       }|j{                  |j                         ||_;        |j                  j"                  j}                  ||j                        S |S )zAnalyse attribute access that does not target a method.

    This is logically part of analyze_member_access and the arguments are similar.

    original_type is the type of E in the expression E.var
    )r   ctxalias_definitionimplicitFzDid not expect a function)__getattr____setattr____getattribute__)r   r   r   defnityper   rR   r\   rb   .r   )rN   r   )lvalue)?lookup_member_var_or_accessorrN   rU   r   rS   rt   r   r   rO   r   r   r"   r$   type_object_typer[   r   r!   expr_checkeralias_type_in_runtime_contextr   get_final_contextcheck_final_memberrT   r   r   r   module_refsaddfullnamemodule_typerP   rI   r   $analyze_decorator_or_funcbase_accessrR   r   rD   r   r1   r   pluginget_attribute_hookr&   rQ   rc   r   r   r   r   r0   r>   r   extra_attrsattrsmod_nameundefined_in_superclassr   r   module_publicr   r   set_lineanalyze_ref_expr)r\   r   r   rb   vvvrv   r   method_namer   bound_methodgetattr_typerw   r   hooksetattr_meth
bound_typesetattr_typeretes                       rW   r   r     s    	&dD",,?AFF1bjj)	
B"i FF;;,"h +B>?"i  ff!!??BJJ @ 
 3!S:&& << 8 8 :tT2662::>4E4hGG	Aw	111u	Ax	 
qzz*vv""..q11JJ""*
 ||B5
 fkk226GG#G##!"$,,($L 4E6;;GC#23J<Y\3]#^L!,=!-!6!6!- #)++"6"6!7q?H66==;;HED!%, /0@0@ A & " "

 "" "MG  CJ  ??=9L 1 1 : :>O OA% ll''%'8
 0|7H7HI./FzSV/WXlL9c,BXBX>Y\]>]'11"55zz!!y--.. TU%6%6%<%<<  ))$$**400	{{
&&tRZZ8y++,,&r'7'7bI ""....**40>>&&t,11AAJJrzz"AF66&&77",,7OO
rY   c                    |j                   D ]J  }|j                  j                  |       }|s!t        |j                        s7|j                  | d|       L y)z?Give an error if the name being assigned was declared as final.T)attr_assignr   N)mronamesgetr%   r   cant_assign_to_final)r\   r   rT   r   basesyms         rW   r   r   y  sE    jjnnT"=*$$Tt$E rY   )
assignmentc          
        t        |j                        }| }t        |       } t        | t              r-t	        | j
                  D cg c]  }t        ||       c}      S t        | t              s|S | j                  j                  d      s|S | j                  j                  d      }||j                  j                  t        j                  j                  | j!                  |j                  j"                              |j$                         t'        t(        j*                        S t-        || | j                  | d|      }t/        | |j0                        }t3        ||      }t        |t4              r4|j7                         r$|j
                  d   j8                  }	t;               }n)t        |t<              r|j>                  }	t;               }n|}	|j@                  jB                  jE                  | d      }
|j@                  jB                  jG                  |
|tI        ||j$                        tI        t=        jJ                  |	      |j$                        gtL        tL        g|j$                  |       }|j@                  jB                  jO                  |tI        ||j$                        tI        t=        jJ                  |	      |j$                        gtL        tL        g|j$                  | |
      \  }}|sO|j@                  jQ                  ||j$                         |j@                  jS                  ||j$                  ||        t        |      }t        |t&              r|S t        |tT              s|j                  j                  t        j                  j                  | j!                  |j                  j"                              |j$                         t'        t(        j*                        S |j8                  S c c}w )aU  Type check descriptor access.

    Arguments:
        descriptor_type: The type of the descriptor attribute being accessed
            (the type of ``f`` in ``a.f`` when ``f`` is a descriptor).
        mx: The current member access context.
    Return:
        The return type of the appropriate ``__get__`` overload for the descriptor.
    __get__r   r   rS   )object_type)r  callable_name)targetselftype)+rD   rR   rt   rC   r,   r   analyze_descriptor_accessr4   r   has_readable_memberr   rT   r   r	   DESCRIPTOR_GET_NOT_CALLABLEr   str_with_optionsoptionsrS   r0   r>   r   r   r   r   r   r3   r   r   r6   r?   r   rU   r   method_fullnametransform_callee_typer    r   r   
check_callcheck_deprecatedwarn_deprecated_overload_itemr1   )descriptor_typerb   r  instance_typeorig_descriptor_typerv   
dunder_getr  dunder_get_type
owner_typer  r   inferred_dunder_get_types                rW   r  r    sQ    $BLL1M*%o6O/9-$;J;P;PQ;PC&sB/;PQ
 	
 2##33I>## %%00;J
88??00@ JJ		
 y++,,7!!!L $OZ__
EC-lC@O-.=3L3L3N"((+44
 
	M8	,"''
 
"
FF''77SMff))??]BJJ7X--j92::N	
 
'


# @ 
O #%&&"5"5"@"@]BJJ7X--j92::N	
 
'


## #A 
#A 

BJJ7
,,

+Co 	- 	
  //GH*G4''.=
88??00@ JJ		
 y++,,#,,,i Rs   Pc                    | j                   | j                  j                  v xrM | j                  j                  | j                      j                  | u xr | j                   xr | j
                   S )z;Return if var is an instance variable according to PEP 526.)r\   r   r  r   is_classvaris_inferred)r   s    rW   is_instance_varr1    sa     	CHHNN" 	 HHNN388$))S0	 	  rY   r   c          	        |}t        ||j                        }|j                  }|rt        |t              r2|j
                  j                  ||j                  ||j                        S |j                  rI|j                  r=|j                  s1|j                  j                  | |j                  |j                         |j                  r2|j                  r&|j                  j                  | |j                         t        |      }t!        ||||      }t#        ||      }t%        |       |}	t'        |      }d}
|j(                  r_t+        |      r|j,                  rHt        |t.              r|j1                         s|}
n%|j                  rt'        t3        d||            }
n|}
t        |
t.              r|
j1                         s|j                  ro|j                  r>|j                  sW|j                  j                  | |j                  |j                         n%|j                  j5                  |j                         |j6                  sL|
}t9        j:                  |j<                  |      }t        |      }t'        t?        |||j<                              }t        |t.              sJ |}tA        |||jB                  |j                  | |j                        }tE        ||jF                  |jB                        }t#        ||      }t%        |       |j                  rt        |tH              sJ |jJ                  }	nZ|}	nW|jL                  s2|jN                  s&|jQ                  |jR                  |j                         tU        tV        jX                        }	|j                  jZ                   d|  }|j
                  j\                  j_                  |      }|	r|j                  s|sta        |	|      }	|rF |tc        t'        |j<                        |	|j                  |j                  |j
                              }	|	S )aZ  Analyze access to an attribute via a Var node.

    This is conceptually part of analyze_member_access and the arguments are similar.
    itype is the instance type in which attribute should be looked up
    original_type is the type of E in the expression E.var
    if implicit is True, the original Var was created as an assignment to self
    N__call__r   )2r   r   r   rt   r9   rU   handle_partial_var_typerN   rS   r   is_settable_propertyrT   read_only_propertyr/  cant_assign_to_classvarr   expand_self_type_if_neededr   r   rD   is_initialized_in_classr1  rP   r3   r   rs   r   is_staticmethodr   r   rQ   r   r   r   r'   rR   r1   r   is_readyrJ   r_   r\   r0   r>   r   r   r   r   r  r&   )r\   r   r   r   rb   r   original_ityperv   trw   	call_typefunctyper   r   boundexpanded_signaturer   r  s                     rW   r   r     s=   " N%eSXX6E
((C
c;'6611#r||S"**UU<<COOC4L4LFF%%dEJJ

C<<COOFF**4<+C0&q"c>B#Au-Qc"'+	&&0D#|,S__5F	+,B:sTV,WX		i.y7L7L7N||??3311$

BJJOFF00<&& *3 #'//"2B2BE"J;HE	'(8iIYIY(Z[!%666!	*0B0BBJJPTVXV\V\	 &is?Q?QR	%<Y%N"$%78??%&8,GGG/88F/F||BNN!!#((BJJ7//0((##$AdV,H66==++H5Dbll8*626 0 0162<<UWU[U[

 MrY   c                   t        |j                        }|j                  sl|j                  s`|j                  }|rEt	        |t
              r|j                  }n(t	        |t              rt        |j                        }n|}t        || |      S t        t        |j                        dd      r7|j                  }|rt	        |t
              r|j                  }t        || |      S |j                  rw|j                  |j                  k7  r^|j                  j                  H||j                  j                  j!                         k(  r!t        || |j                  j                        S | S )zExpand special Self type in a backwards compatible manner.

    This should ensure that mixing old-style and new-style self-types work
    seamlessly. Also, re-bind new style self-types in subclasses if needed.
    F)allow_instancesallow_callable)rD   rR   rK   rO   rt   r?   r   r1   r   r   r   r-   r   r   rU   scopeactive_self_type)r=  rb   r   r   r   originalrepls          rW   r8  r8  Y  s    r||,HJJ"++||(H-}}Hl3%h&7&78Q--	%	
 ||
8X6==DQ--


JJ#((" JJ  ,RVV\\2244Q

(<(<==rY   c                6    | j                  t                      y rM   )acceptFreezeTypeVarsVisitor)r   s    rW   r   r     s    ,./rY   c                        e Zd Zd fdZ xZS )rK  c                h    |j                   D ]  }d|j                  _         t        |   |       y )Nr   )r   id
meta_levelsupervisit_callable_type)rV   r=  r  	__class__s      rW   rQ  z)FreezeTypeVarsVisitor.visit_callable_type  s)    AADDO #A&rY   )r=  r1   rh   ri   )rk   rl   rm   rQ  __classcell__)rR  s   @rW   rK  rK    s    ' 'rY   rK  c                B    | j                  |      }|r|j                  S y)zCFind the attribute/accessor node that refers to a member of a type.N)r  r   )r   r\   rN   r   s       rW   r   r     s!     88D>DyyrY   c           	     f   | j                   }|s| S g }|rt        j                  |      }|D ]  }|j                  r|j                  d   t
        t        fvr|j                  |||       | c S t        |j                  d         }	t        j                  |t        t        |	                  r|j                  |       t        |	t              r|j                  |       t        |	t               st"         |s|j%                  |||d   ||       | S t'        |      dk(  r|d   S t)        |      S )a  Check that an instance has a valid type for a method with annotated 'self'.

    For example if the method is defined as:
        class A:
            def f(self: S) -> T: ...
    then for 'x.f' we check that meet(type(x), A) <: S. If the method is overloaded, we
    select only overloads items that satisfy this requirement. If there are no matching
    overloads, an error is generated.

    Note: dispatched_arg_type uses a meet to select a relevant item in case if the
    original type of 'x' is a union. This is done because several special methods
    treat union types in ad-hoc manner, so we can't use MemberContext.self_type yet.
    r   r   )r   r?   r   r   r   r   r   no_formal_selfrD   r
   
is_subtyper   r)   r   rt   r8   rA   NotImplementedErrorincompatible_self_argumentr   r7   )
r?  dispatched_arg_typer   rS   r\   rT   r   	new_itemsr   selfargs
             rW   r   r     s!   * NNEI&667JK~~!27H:M!MtT73 O%dnnQ&78G ""#6~V]G^8_`  &G]3  &G%56))# $ &&%uQx	
 
9~|i  rY   )rp   r   c          
     @   | j                   }|r|}|j                   d| }|j                  j                  j	                  |      }|j                  |      }	|	s| j                  rG|| j                  j                  v r/| j                  j                  s| j                  j                  |   S |j                  s|j                  r$t        ||t        t        j                              S yt        |	j                   t"              r4|	j                   j$                  s|s|j                   j                  |      ry|j                  j'                  |	j                   |j(                         t        |	j                   t*              }
|
xs t        |	j                   t,              }|j.                  ru|r%|j0                  j3                  |j(                         t        |	j                   t4              r4|j0                  j7                  t8        j:                  |j(                         |j<                  rQ||j<                  v rC|j0                  j7                  t8        j>                  jA                  |      |j(                         |	jB                  rt        |	j                   t"              rm|	j                   jD                  rW|j0                  j7                  t8        jF                  jA                  |	j                   jH                        |j(                         |j.                  r<|j                  jK                         s"tM        |||j0                  |j(                         |jN                  r,|j.                  s |
s|stQ        | ||      }|rt        |||      S |	j                   }|rt        |tR              r[|	j                   }t        |t"              sJ t        |||j                  jU                  ||j.                  ||j(                              S t        |	j                   t*              r!|	j                   jV                  jX                  }n9t        |	j                   t"        tZ        f      r|	j                   jX                  }nd}|sd}nt]        | |      }t        |	j                   t"              r|J t_        |	j                   jX                  j`                  jb                        }|	j                   j$                  sO|	j                   jX                  jd                  r/|jg                  |	j                   jX                  jd                         t_        ti        |            }||z  rt        tk        |jl                        tn              r|	jB                  r]|	j                   j$                  rt8        jp                  }nt8        jr                  }|j0                  j7                  ||j(                         tu        |||	j                   | d      }tw        ty        ||      |D ch c]  }|jz                   c}      }|
xr. t}        t*        |	j                         j~                  j                  xs2 t        |	j                   t,              xr |	j                   j                  }|
xr. t}        t*        |	j                         j~                  j                  xs2 t        |	j                   t,              xr |	j                   j                  }tk        |      }t        |t              r0|r.t        ||jd                  d|j(                  ||j0                        }t        |||||jd                  |      }|j.                  st        ||      }t        |||      S t        |	j                   t"              r5|j                  ||j(                         t        t        j                        S t        |	j                   t              rg|j0                  j7                  t8        j                  jA                  |jH                  |      |j(                         t        t        j                        S t        |	j                   t4              r t        |	j                   |j                        S t        |	j                   t              r|j                  d      S t        |	j                   t              rF|j                  j                  j                  |	j                   |j(                  |j.                        S |
rt        |	j                   t*              sJ |	j                   j                   r!t        |||	j                   j                         S |j                  ||j(                         t        t        j                        S t        |	j                   t,              sJ t        |	j                   |j                  d	            }|	j                   j                  rt        |d
      }t        |||      S c c}w )a   Analyze access to an attribute on a class object.

    itype is the return type of the class object callable, original_type is the type
    of E in the expression E.var, original_vars are type variables of the class callable
    (for generic classes).
    r   NT)r   Fr   ztypes.ModuleTyper   r   r   )Rr   r   rU   r   get_class_attribute_hookr  r   r   r   r   meta_fallback_to_anyapply_class_attr_hookr0   r>   r   rt   r   r$   r/  r   rS   r   r   rN   rT   r   r"   r   r	   CANNOT_ASSIGN_TO_TYPEslotsCLASS_VAR_CONFLICTS_SLOTSr   r   is_final!CANNOT_ACCESS_FINAL_INSTANCE_ATTRr\   r   r   is_enum#analyze_enum_class_attribute_accessr9   r4  r   r   r   r   setr   	type_varsrR   r   r+   rD   rQ   r?   GENERIC_CLASS_VAR_ACCESS!GENERIC_INSTANCE_VAR_CLASS_ACCESSr8  r   r   rN  r   r   r   r   r3   r   add_class_tvarsr  r_   r#    CANNOT_USE_TYPEVAR_AS_EXPRESSIONr   r   r[   r   r!   r   r   r*   r'   )r   r\   rb   r   rp   r   r   r   r  r   is_decorated	is_methodenum_class_attribute_typer=  symnode
super_infoisuperdef_varstyp_varsmessagetvr   r:  rw   rv   s                            rW   r   r     s1    ::D--$(H66==11(;D88D>D):):)@)@!@$$--((..t444#<#<(T79;Q;Q3RSS 	499c"		%%!!$' FF499bjj1dii3L?
499h ?I	||FF((4dii*FFKK(>>

K zzddjj(
$>>EEdKRZZX }}DIIs3		8J8J
>>EEdiinnUWYWaWa	
 
||BFF4464rvvrzz:||R\\\Y$GtUW$X!$(T3LMM		Aa%iiGgs+++(D"&&88BLL'SUS]S]^ 
 dii+*.))--*<*<J		C)>#?@JJ F.ujAFdii%%%% 499>>..889H99((TYY^^-E-ETYY^^556=+,H("!/"2B2B"CXNRVR_R_yy,,"2"K"K"2"T"TFFKK4*1b$))UTRA
 6q&AT\C]T\bBEET\C]^A&S4	499+E+J+J+S+S 
tyy(+B		0B0B 	 (UDDII,F,K,K,U,U 
tyy(+C		0C0C 	 Aa&>q",,rzz4PA v~Ta
 ||.vr:F$Rv66	DIIs	#
dBJJ/y--..$))[)
==DDTYYPTUWYWaWa	
 y++,,$))X&		2==99$))X&}}/00$))Y'vv""@@II2:: A 
 	
 $))Y///99>>(T499>>BB!!$

39//00$))X...DIIr}}5H'IJ 99C5C$Rs33o D^s   h
c           	         |rF |t        t        | j                        || j                  | j                  | j
                              }|S rM   )r&   rD   rQ   rN   rS   rU   )rb   r  rw   s      rW   ra  ra    sE      0 0162<<UWU[U[

 MrY   c                   |t         v rt        |j                  | ||      S |j                  d      r|j	                  dd      dk7  ry | j
                  j                  |      }|re|j
                  rYt        |j
                        }t        |t              r4|j
                  j                  dk(  r|j                  r|j                  d   S t        ||       }| j                  |      S )N__r    zenum.nonmemberr   r   )ru   )r   r   rQ   
startswithreplacer   r  rD   rt   r4   r   argsr5   rc   )r   r\   rb   r   properenum_literals         rW   rh  rh    s     '''(8(8%rJJtc2!6"!<::>>$D		 + vx($$(88;;q>!te4L==rY   c           	        | dk(  rt        |j                  t              rx|j                  j                  j                  ||j                  j                  d      \  }}|j                  |z  }|rA|j                  j                  ||j                         nt        t        j                        }t        |j                  j                  d      |gt        t        gd d gt!               |j                  j                  d      |       S | dk(  rRt        |j                  j                  d      gt        gd gt!               |j                  j                  d      |       S t#        | |j$                  ||      S )	N__setitem__T)setitemr  zbuiltins.strr   )r   r   r   r   r   r\   __delitem__)rt   rS   r   rU   r   visit_typeddict_index_exprindexreadonly_keysrT   readonly_keys_mutatedr0   r>   implementation_artifactr1   r[   r   r6   rs   r   )r\   rv   rb   rp   	item_type	key_namesassigned_readonly_keyss          rW   r   r     sL    }bjj), $&66#6#6#Q#QRZZ%%t $R $ Iy &)%6%6%B"%,,-CRZZ,X  	 A ABIvv((8)D(TlZVV&&':;
 	
 
	vv((89ifZVV&&':;
 	
 "$b-HHrY   c                   t        | t              rq||ng }t        |       } |rt        | |d      } |s|r|J t	        | |      } t        |        | j                  t        |      t        | j                        z         S t        | t              r@t        | j                  D cg c]!  }t        t        t        ||||||            # c}      S |t	        | |      } | S c c}w )a  Instantiate type variables during analyze_class_attribute_access,
    e.g T and Q in the following:

    class A(Generic[T]):
        @classmethod
        def foo(cls: Type[Q]) -> Tuple[T, Q]: ...

    class B(A[str]): pass
    B.foo()

    Args:
        t: Declared type of the method (or property)
        isuper: Current instance mapped to the superclass where method was defined, this
            is usually done by map_instance_to_supertype()
        is_classmethod: True if this method is decorated with @classmethod
        is_staticmethod: True if this method is decorated with @staticmethod
        original_type: The value of the type B in the expression B.foo() or the corresponding
            component in case of a union (this is used to bind the self-types)
        original_vars: Type variables of the class callable on which the method was accessed
    Returns:
        Expanded method type with added type variables (when needed).
    Tr   )r   r^  )rt   r1   r   r'   r   r   rc   listr   r7   r   r   rm  )r=  rt  r   r:  rQ   r   tvarsr   s           rW   rm  rm    s    X !\"!.!:+A.!]4@A_%%%'62AQetAKK7H)HII	Az	" GG $D  #&'%&3
 $
 	
  #Av.H#s   %&C"c           	        | j                  d      }| j                  d      }|rt        |j                        st        t        j
                        S |xs |}t        |j                        st        t        j
                        S t        |j                  t        t        f      sJ t        |j                  t        t        f      sJ | j                  j                  |j                  j                        }| j                  j                  |j                  j                        }| j                  xs  |d      }||k  r|j                  }d}n||kD  r|j                  }d}n|j                  j                  j                  dk(  rY| j                  rMt        t        j                        }	t!        |	|	gt"        t$        gddg|	 |d	      
      }
t'        |
| |dd      S |j                  }d}t        |t(              rt+        ||      }nDt        |j,                  t.              sJ t        |j,                  t0              sJ |j,                  }t3        || |j                  ||      S )a9  Return the type of a type object.

    For a generic type G with type variables T and S the type is generally of form

      Callable[..., G[T, S]]

    where ... are argument types for the __init__/__new__ method (without the self
    argument). Also, the fallback type will be 'type' instead of 'function'.
    rX   __new__r   FTr   _args_kwdsr   r   N)is_new)r  is_valid_constructorr   r0   r>   r   rt   r   r   r  r  r   r   r   r   r   r1   r   r   r(   r   r*   r   r:   r3   r/   )r   r[   init_method
new_method
init_index	new_indexr   r   r  any_typesigr=  s               rW   r   r   (  s    ((:&K)$J2;3C3CDy++,, *{J
0y++,, joo(=y'IJJJk&&)>	(JKKK 0 0 5 56Jz334I""Aj&AHI'2'7'7	i	  ))->> ##"9#9#9:"'2'3&0%'(;< &c44NN
 !! &(#&(+&++z222&++|444KK)!T6;;&QQrY   c                    t        | t              rt        || j                  |||      S t	        t        | |j                  j                  d            |      S )zAnalyzes the type behind method access.

    The function itself can possibly be decorated.
    See: https://github.com/python/mypy/issues/10409
    r   )rQ   )rt   r   r   r   r'   r*   rU   r[   r   s         rW   r   r   o  sO     $	"45$;;dBFF--.ABCS\ rY   c                    t        | t              ryt        | t              r#t        t        | j                        t
              S y)zDoes this node represents a valid constructor method?

    This includes normal functions, overloaded functions, and decorators
    that return a callable type.
    TF)rt   r   r   rD   r   r3   )ns    rW   r  r    s4     !X!Y/!&&1<@@rY   ) r\   rj   rv   r<   rS   r   rN   rd   rO   rd   rP   rd   rT   r   rQ   r<   rU   re   rp   TypeInfo | Nonerq   rd   rR   rf   rI   rg   rJ   rd   rK   rd   rh   r<   rM   )
r\   rj   rv   r<   rb   rH   rp   r  rh   r<   )
r\   rj   rv   r<   rb   rH   rp   r  rh   rd   )rQ   r<   rv   r<   r\   rj   rb   rH   rp   r  rh   r<   )
r\   rj   rv   r4   rb   rH   rp   r  rh   r<   )r   r   rb   rH   rh   ri   )r\   rj   rv   r3   rb   rH   rh   r<   )
r\   rj   rv   r?   rb   rH   rp   r  rh   r<   )r\   rj   rv   rC   rb   rH   rh   r<   )r\   rj   rv   r6   rb   rH   rh   r<   )
r\   rj   r   r4   r   r"   rb   rH   rh   r<   )
r\   rj   r   r"   rT   r   r   r   rh   ri   )r'  r<   rb   rH   r  rd   rh   r<   )r   r$   rh   rd   )r\   rj   r   r$   r   r4   r   r"   rb   rH   r   rd   rh   r<   )F)r=  r<   rb   rH   r   r$   r   r4   r   rd   rh   r<   )r   r<   rh   ri   )r   r"   r\   rj   rN   rd   rh   SymbolNode | None)r?  r3   rZ  r<   r   rd   rS   r   r\   rj   rT   r   rh   r3   )r   r4   r\   rj   rb   rH   r   r4   rp   r  r    Sequence[TypeVarLikeType] | Nonerh   rf   )rb   rH   r  z)Callable[[AttributeContext], Type] | Nonerw   r<   rh   rf   )r   r4   r\   rj   rb   rH   rh   rf   )
r\   rj   rv   r=   rb   rH   rp   r  rh   r<   )r=  r:   rt  zInstance | Noner   rd   r:  rd   rQ   r<   r   r  rh   r<   )r   r"   r[   zCallable[[str], Instance]rh   r:   )r   zDecorator | FuncBaser   r4   r   r"   rR   rf   r\   rj   rb   rH   rh   r<   )r  r  rh   rd   )orn   
__future__r   typingr   r   r   r   mypyr   r	   r
   mypy.erasetyper   mypy.expandtyper   r   r   mypy.maptyper   mypy.messagesr   
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   mypy.pluginr&   mypy.typeopsr'   r(   r)   r*   r+   r,   r-   r.   r/   
mypy.typesr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   mypy.typetraverserrE   mypy.checkerrF   rH   ry   rs   r   r   r|   r   r   r   r~   r   r   r   r  r1  r   r8  r   rK  r   r   r   ra  rh  r   rm  r   r   r  ro   rY   rW   <module>r     s^   ' " : : 1 1 ) 
 3 (     . )
 
 
     . 4 C Cb &*$!.2!?
?	? ?
 ? ? ? 
? ? 
"? #? ? ? ,? ?  !?" 
#?F OS$E
$E$E+$E<K$E	$EP OS1
11+1<K1	1( &*))	) ) 		)
 #) 
)$B>
B>B>"/B>@OB>	B>J
C!6H5I
5I5I"/5I@O5I	5Ip*RN
NN&.N4AN	NbF EJg-g-,g-=Ag-	g-T	& _
_	_ _ 	_
 	_ _ 
_F MR)))%()19)EI)	)X0'0 '6!6!6! 6! 	6!
 6! 
6! 6!~ &*6:z4z4
z4 	z4
 z4 #z4 4z4 z4z		F	PT		>>>$1>>2$I
$I!$I'4$IET$I	$IZ 7;III I 	I
 I 4I 
IXDRN
  	
  	 
(
rY   