
    X-Ph              	         d Z ddlmZ ddlmZ ddl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 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/m0Z0 ddl1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ  G d d          ZRddddddddddud.ZS	 dvdwd0ZT	 dvdxd1ZU	 dvdyd2ZVdzd4ZWd{d8ZXd|d:ZYd}d<ZZd~d>Z[dd@Z\ddDZ]ddHZ^ddJZ_ddKZ`ddNZadddOddRZbddTZcddVZd	 dddYZedd\Zfddd]ddaZgddeZhddfZiddhZj	 	 dddmZkddpZl edqe@r          ZmdvddtZndS )z!Type checking of attribute access    )annotations)Sequence)CallableTypeVarcast)message_registrystatesubtypes)TypeCheckerSharedApi)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
ExpressionFuncBaseFuncDef	IndexExprMypyFileNameExprOverloadedFuncDefSymbolTableTempNode	TypeAliasTypeInfoTypeVarExprVaris_final_node)AttributeContext)
	bind_selferase_to_boundfreeze_all_type_varsfunction_typeget_all_type_varsget_type_varsmake_simplified_unionsupported_self_typetuple_fallbacktype_object_type)AnyTypeCallableTypeDeletedTypeFunctionLikeInstanceLiteralTypeNoneType
OverloadedParamSpecTypePartialType
ProperType	TupleTypeTypeTypedDictType	TypeOfAnyTypeTypeTypeVarLikeTypeTypeVarTupleTypeTypeVarType	UnionTypeget_proper_typec                  T    e Zd ZdZdddddddd%dZd&dZd'dZd(d!Zdddd"d)d$ZdS )*MemberContextzInformation and objects needed to type check attribute access.

    Look at the docstring of analyze_member_access for more information.
    NF)	self_typemodule_symbol_tableno_deferralis_selfrvaluesuppress_errors	is_lvalueboolis_superis_operatororiginal_typer>   contextr   chkr   rI   Type | NonerJ   SymbolTable | NonerK   rL   rM   Expression | NonerN   returnNonec                   || _         || _        || _        || _        |p|| _        || _        || _        |j        | _        || _        |	| _	        |
| _
        ||sJ || _        || _        d S N)rO   rQ   rR   rS   rI   rT   rU   msgrJ   rK   rL   rM   rN   )selfrO   rQ   rR   rS   rT   rU   rI   rJ   rK   rL   rM   rN   s                P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/checkmember.py__init__zMemberContext.__init__U   s      # &*"3m7#6 &.    namestrr6   c                6    | j                             |          S r\   )rU   
named_type)r^   rb   s     r_   re   zMemberContext.named_typeu   s    x""4(((ra   c                <    | j                             ||           d S r\   )rU   handle_cannot_determine_type)r^   rb   rT   s      r_   not_ready_callbackz MemberContext.not_ready_callbackx   s     --dG<<<<<ra   r]   c                X    | j         s"| j                            || j                   d S d S r\   )rN   r]   failrT   )r^   r]   s     r_   rj   zMemberContext.fail{   s5    # 	-HMM#t|,,,,,	- 	-ra   )rI   rO   rS   bool | Nonec                   t          | j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
        | j                  }|||_        |||_        |||_        |S )N)rO   rQ   rR   rS   rT   rU   rI   rJ   rK   rM   rN   )rH   rO   rQ   rR   rS   rT   rU   rI   rJ   rK   rM   rN   )r^   rI   rO   rS   mxs        r_   copy_modifiedzMemberContext.copy_modified   s     n](,Ln $ 8(; 0
 
 
  $BL $BL$,B	ra   )rO   rP   rQ   rP   rR   rP   rS   r>   rT   r   rU   r   rI   rV   rJ   rW   rK   rP   rL   rP   rM   rX   rN   rP   rY   rZ   )rb   rc   rY   r6   )rb   rc   rT   r   rY   rZ   )r]   rc   rY   rZ   )rI   rV   rO   rk   rS   rV   rY   rH   )	__name__
__module____qualname____doc__r`   re   rh   rj   rn    ra   r_   rH   rH   O   s          "&26!$( %/ / / / / /@) ) ) )= = = =- - - - "&!%%)       ra   rH   NF)override_infoin_literal_contextrI   rJ   rK   rL   rM   rN   rb   rc   typr>   rT   r   rO   rP   rQ   rR   rS   rU   r   rt   TypeInfo | Noneru   rI   rV   rJ   rW   rK   rL   rM   rX   rN   rY   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)

    'rvalue' can be provided optionally to infer better setter type when is_lvalue is True,
    most notably this helps for descriptors with overloaded __set__() method.

    'suppress_errors' will skip any logic that is only needed to generate error messages.
    Note that this more of a performance optimization, one should not rely on this to not
    show any messages, as some may be show e.g. by callbacks called here,
    use msg.filter_errors(), if needed.
    )rO   rQ   rR   rS   rT   rU   rI   rJ   rK   rL   rM   rN   )rH   _analyze_member_accessrF   
isinstancer6   last_known_value)rb   rv   rT   rO   rQ   rR   rS   rU   rt   ru   rI   rJ   rK   rL   rM   rN   rm   resultpossible_literals                      r_   analyze_member_accessr~      s    d 
#/'
 
 
B $D#r=AAF&v..'22 -900ra   rm   c                   t          |          }t          |t                    rt          | |||          S t          |t                    rt	          t
          j        |          S t          |t                    rt          | ||          S t          |t                    r%|
                                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.                    rWt          |t0                    r+|j        r$t          | t5          |j                  ||          S t          | |j        ||          S t          |t8                    r@|j        s |j                            ||j                    t	          t
          j!                  S tE          |j#        || |          S )N)
source_any)$rF   rz   r6   analyze_instance_member_accessr2   r@   from_another_anyrE   analyze_union_member_accessr5   is_type_obj#analyze_type_callable_member_accessrA   analyze_type_type_member_accessr=   ry   r0   r7   fallbackr?   analyze_typeddict_accessr8   analyze_none_member_accessrB   rD   valuesr.   upper_boundr4   rN   r]   deleted_as_rvaluerT   
from_errorreport_missing_attributerS   )rb   rv   rm   rt   s       r_   ry   ry      sM   
 #

C#x   --dC]KKK	C	!	! -y1cBBBB	C	#	# -*4b999	C	&	& -3??+<+< -24bAAA	C	"	" -.tS"mLLL	C	#	# -%dN3,?,?]SSS	C+|4	5	5 -%dCL"mLLL	C	'	' -'c2}EEE	C	"	" -)$R888	C	)	) 	-c;'' 	CJ 	)+CJ77]   &dCOROOO	C	%	% -! 	6F$$S"*555y+,,,#B$4c4DDDra   c           	        |j         j        rdS |j                                         5  |j                                        5 }|j                             ||          }|	 ddd           ddd           dS t          | ||                    |          |          }|                                 cddd           cddd           S # 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z7Check if the given type has the attribute when awaited.FNrI   )	rU   checking_missing_awaitchecking_await_setr]   filter_errorsget_precise_awaitable_typery   rn   has_new_errors)rb   rv   rm   rt   local_errorsaw_type_s          r_   may_be_awaitable_attributer     s    
v$ u		"	"	$	$ 1 1bf&:&:&<&< 1&33CFF?1 1 1 1 1 1 1 1 1 1 1 1 1 1 #'2++g+>>
 
  ..0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1sA   C$C!C$9:C3C$C	C$C	C$$C(+C(c                Z   |j         rt          t          j                  S |j                            | |||j        |j                  }|j                                        s2t          ||||          r |j        
                    |j        |           t          t          j                  S r\   )rN   r2   r@   r   r]   has_no_attrrT   rJ   prefer_simple_messagesr   possible_missing_await)rS   rv   rb   rm   rt   
error_codes         r_   r   r   !  s     
 -y+,,,##M3bj"J`aaJ6((** B%dC]CC 	BF))"*jAAA9'(((ra   r6   c                   |j         }|r|}|                    |           }| dk    rO|j        sH|j        sA|r|j        s8|                    t
          j                   t          t          j	                  S t          j        rj|j        t          j        d         k    rO| t          j        d         k    r9|j        s2|j                             dj        t          j         |j                   |rtt%          |t&                    s^|j        r|j        st)          ||           |j        rt%          |t,                    sJ |j        d         }t%          |t&                    sJ |j        r@t3          |j        x}          dk    r&|j                            |d         |j                   t9          | |j        ||          S |j        r&|j        s|j                            |j                   t%          |t,                    s$t?          ||                     d                    }nq|j         G|j!        s'|j        r |"                    |j        |j                   t          t          j#                  S t%          |j         tH                    sJ |j         }tK          |          }|j&        s}t%          |tN          t,          f          r|j(        rtS          ||j*                  }nDtW          ||j*        |j,        |j        | |j                  }t[          ||j*        |j,                  }t]          ||j/                  }ta          ||          }	tc          |	           |	S te          | |||          S )Nr`   r      zOccurrence of '{}.{}'builtins.functionis_classmethod)3type
get_methodrQ   is_finalrj   r   CANNOT_ACCESS_INITr2   r@   r   r	   find_occurrencesrb   rN   r]   noteformatrT   rz   r   validate_super_callis_propertyr   itemsrO   lenrU   warn_deprecatedanalyze_varvarcant_assign_to_methodr+   re   rK   rh   special_formr9   r   	is_staticr   is_trivial_selfbind_self_fastrI   check_self_argis_classr(   r   infor   r*   analyze_member_var_access)
rb   rv   rm   rt   r   methodgetterr   	signaturemember_types
             r_   r   r   5  sa    8D __T""Fz"+dm 	1V_ 	1 GG$78889/000
 	YI/222E*1---" . 	2+2E4JKRZXXX  *>j33 *>; 	,r1 	,+++ 	:f&788888\!_Ffi00000| =fl%:U!;!;a!?!?&&uQx<<<tVZb999< 	5 2 	5F((444&"344 
	$%fbmm<O.P.PQQII{" ~ C&, C))&+rzBBBy5666fk:66666I3I>>	 	_&7,=">?? _FDZ _*9blCC		*r|V_bj$PRPV 	 &ifo^^^	 (V[99-i==[))) )sD"===ra   noder   rZ   c                   d}t          | t                    r
| j        rd}nt          | t                    r| j        r5t          | j        t                    r| j        n| j        j        }|j        }nG| j        s@| j        r9t          | j        d         t                    sJ | j        d         j        j        }|r2|j	        
                    | j        | j        j        |j                   d S d S )NFTr   )rz   r   is_trivial_bodyr   implfuncr   r   r   r]   unsafe_superrb   r   rT   )r   rm   r   r   s       r_   r   r   }  s    L$   >T%9 >	D+	,	, >9 	> *49g > >R499DIND/LL! 	>dj 	>djmY77777:a=-=L C
DIty~rzBBBBBC Cra   r5   c                   |j         d         j        }t          |t                    sJ t          |t                    rt          |          }t          |t                    r|j        }t          |t                    rJ|j	        s-t          || ||j         d         j        |j                  }|r|S t          | |j        |          S J d|            )Nr   )original_varsmcs_fallbackFzUnexpected type )r   ret_typerz   r<   r=   r0   r?   r   r6   rR   analyze_class_attribute_access	variablesry   )rb   rv   rm   r   r|   s        r_   r   r     s     y|$Hh
+++++(I&& ,!(++(M** %$(H%% 6~ 	 4$#)A,2HWZWc  F  %dCL"===5555555ra   rA   c                &   d }|                     d          }t          |j        t                    r	|j        }n.t          |j        t                    rE|j                                        5  t          | |||          cd d d            S # 1 swxY w Y   nt          |j        t                    rt          |j        j
                  }t          |t                    r|}nt          |t                    r1t          | t          j        ||j        |j                  ||          S t          |t                     rt#          |          }nt          |t                    rC|j                                        5  t          | |||          cd d d            S # 1 swxY w Y   nt          |j        t                     rt#          |j                  }nt          |j        t$                    r&|j                                        r|j        j        }nOt          |j        t                    r5t          |j        j        t                    r|j        j        j        j        }d}||j        j        p|}|rO|j        sHt1          || |||          }|r2t          t          |          t                    r|j        j        s|S d}|j                            |          5  t          | |||          cd d d            S # 1 swxY w Y   d S )Nzbuiltins.type)linecolumnF)r   rt   T)r   )re   rz   itemr6   r2   r]   r   ry   rD   rF   r   rE   rA   make_normalizedr   r   r=   r0   r5   r   r   r   metaclass_typerR   r   fallback_to_any)	rb   rv   rm   rt   r   r   r   ignore_messagesr|   s	            r_   r   r     s    D}}_--H#(H%% 5x	CHg	&	& 5V!!## 	M 	M)$"mLL	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M	CHk	*	* 5%ch&:;;k8,, 	QDDY// 	Q)(38CJWWW	   Y// 	Q!+..DDW-- 	Q%%'' Q Q-dHb-PPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q	CHi	(	( 5ch''	CHl	+	+ 50D0D0F0F 5x 	CHh	'	' 5chmX.. 	58=%4DO9+7x 
'BN 
'/$
 
 
  	'v66@@ 'TYE^ ' #'			O		<	< I I%dHb-HHI I I I I I I I I I I I I I I I I Is6   .BBB FF#&F#'LL
L
rE   c           	     *   |j                                         5  g }|                                D ]<}|                    |          }|                    t          | ||                     =	 d d d            n# 1 swxY w Y   t          |          S )Nr   )r]   disable_type_namesrelevant_itemsrn   appendry   r.   )rb   rv   rm   resultssubtypeitem_mxs         r_   r   r     s    		"	"	$	$ K K))++ 	K 	KG&&&99GNN1$IIJJJJ	KK K K K K K K K K K K K K K K !)))s   AA;;A?A?r8   c           	         | dk    rKt          d|                    d                    }t          g g g ||                    d                    S t          | |                    d          |          S )N__bool__Fzbuiltins.boolr   r   )	arg_types	arg_kinds	arg_namesr   r   builtins.object)r7   re   r3   ry   )rb   rv   rm   literal_falses       r_   r   r     s    z#EBMM/4R4RSSS"]]#677
 
 
 	
 &dBMM:K,L,LbQQQra   ityper   r#   c           
     
   |                     |           }|r|j        nd}|j                            ||j                   |}d}t          |t                    r>|j        }|j        j	        o|j
         }|j        r|j        st          |j        |           t          |t                    r+t          | t!          ||j                            }||_        t          |t&                    rD|j        j                            ||j        |j                  }t          | |          }||_        t          |t                    r^||          j        }	|j        r5|j                                        st3          | ||j        |j                   t7          | ||||	|          S t          |t8                    r
J d            t          |t:                    rC|j        j                            |j                    |j        j        !                    |          S t          |tD                    r|j                            d          S |s| dvr|j#        s|j$        |j        sd	D ]}
|%                    |
          }|r|j        j         d
k    rtM          |||
|          }tO          ||j                  }tQ          tS          ||                    }t          |tT                    r|j+        }n|}|j        j          d|  }|j        j,        -                    |          }|r= |t]          tQ          |j/                  ||j        |j        |j                            }|c S n|%                    d          }|r|j        j         d
k    rtM          ||d|0                    d                    }tO          ||j                  }tQ          tS          ||                    }t          |tT                    r%tc          |j2                  dk    r|j2        d         S |j3        j4        rtk          tl          j7                  S |j8        r,| |j8        j9        v r|j8        j:        s|j8        j9        |          S |j        r@|j        s9|j        ;                    | |j                   tk          tl          j<                  S t{          |j/        || |          }|j$        | |j$        v rz|j$        |          j>        sh|j$        |          j        }t          |           }|@                    |j                   ||_        |j        j        A                    ||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
    NF)r   ctxalias_definitionimplicitr   zDid not expect a functionztyping.TypeVar)__getattr____setattr____getattribute__)r   r   r   defnr   rb   rm   .r   )rO   r   )lvalue)Bgetr   rU   r   rT   rz   r   r   r   r   
decoratorsrQ   rN   r   r#   r%   r1   re   r   r"   expr_checkeralias_type_in_runtime_contextrO   r   get_final_contextcheck_final_memberr]   r   r   r   module_refsaddfullnamemodule_typer$   rR   rJ   r   $analyze_decorator_or_funcbase_accessr   rF   r   r3   r   pluginget_attribute_hookr'   rS   rn   r   r   r   r   r2   r@   r   extra_attrsattrsmod_nameundefined_in_superclassr   r   module_publicr   set_lineanalyze_ref_expr)rb   r   r   rm   r   vvvr   rv   r   method_namer   bound_methodgetattr_typer|   r   hooksetattr_meth
bound_typesetattr_typeretes                         r_   r   r      s    88D>>D#		tAF1bj)))	
BO"i   -F'1G"-6G; 	-r1 	-,,,"h  +B>>???"i    f!??BJ @ 
 
 3!S E6:& < 	? 8 8 : : 	?tT262:>>>4E2Rabbbb	Aw		 <611111	Ax	 	  :6
qz***v"..q111	A{	#	# 76v  !122256JJJ K"*
 | ,	6B " "55
  "fk26GGG#G#5{r$ $ $L 4E6;GGC#23J<Y\3]3]#^#^L!,== .!-!6!- #)+"6????H6=;;HEED 	!%, /0@ A A & " "
 " " " "MMM="@  ??=99L 
6 1 :>O O OA%&''%'88	  
 0|7HII./FzSV/W/WXXlL99 6c,BX>Y>Y\]>]>]'1"55z! /y-...  1TU%6%<<< ) 	1$*400	{ 2- 
&&tRZ888y+,,,&r'7bII "....*40> / &t,1AAJJrz"""AF6&77",7OOO
ra   r]   r   r   c                    |j         D ]J}|j                            |           }|r,t          |j                  r|                    | d|           KdS )z?Give an error if the name being assigned was declared as final.T)attr_assignr   N)mronamesr   r&   r   cant_assign_to_final)rb   r   r]   r   basesyms         r_   r   r     sk     F FjnnT"" 	F=** 	F$$Tt$EEEF Fra   descriptor_typec           
     J   t          j                  }| }t          |           } t          | t                    r t	          fd| j        D                       S t          | t                    s|S j        s| j        	                    d          s|S j        r*| j        	                    d          rt          |           S j        r| j        	                    d          s|S | j                            d          }|h                    t          j                            |                     j        j                                       t'          t(          j                  S t-          || d                    |                     }t1          | |j                  }t5          ||          }t          |t6                    r5|                                r!|j        d         j        }t=                      }n-t          |t>                    r|j         }t=                      }n|}j!        j"        #                    | d          }	j!        j"        $                    |	|tK          |j&                  tK          t?          j'        |          j&                  gtP          tP          gj&        | 	          }j!        j"        )                    |tK          |j&                  tK          t?          j'        |          j&                  gtP          tP          gj&        | |	
          \  }
}j!        *                    |j&                   j!        +                    |j&        ||            t          |          }t          |t&                    r|S t          |tX                    sh                    t          j                            |                     j        j                                       t'          t(          j                  S |j        S )a]  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__/__set__`` overload for the descriptor.
    c                0    g | ]}t          |          S rs   )analyze_descriptor_access).0rv   rm   s     r_   
<listcomp>z-analyze_descriptor_access.<locals>.<listcomp>  s$    QQQC&sB//QQQra   __get____set__Nr   r   r   rT   object_typer!  callable_nametargetselftype)-rF   rI   rz   rE   r.   r   r6   rO   r   has_readable_memberanalyze_descriptor_assignr   rj   r   DESCRIPTOR_GET_NOT_CALLABLEr   str_with_optionsr]   optionsr2   r@   r   r   rn   r   r   r   r5   r   r   r8   rA   r   rU   r   method_fullnametransform_callee_typer!   rT   r   r   
check_callcheck_deprecatedwarn_deprecated_overload_itemr3   )r  rm   instance_typeorig_descriptor_type
dunder_getr  rv   dunder_get_type
owner_typer#  r   inferred_dunder_get_types    `          r_   r  r    s    $BL11M*%o66O/9-- $$QQQQ?;PQQQ
 
 	
 22 $##< $ 4 H H S S $## 
| >,@@KK >("===	| $O0DDYOO $## %00;;J
8??00@@ 	
 	
 	

 y+,,,7o66	  L $OZ_
E
EC-lC@@O-.. #=3L3L3N3N #"(+4
 

	M8	,	, #"'
 

"
F'77SSMf)??]BJ777X-j992:NNN	
 
'

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

## #A 
# 
#A FJ
333F((BJ'?/ )     //GHH*G44 (''.== -
8??00@@ 	
 	
 	

 y+,,,#,,ra   c           	        t          |j                  }| j                            d          }|m|                    t
          j                            |                     |j	        j
                            j                   t          t          j                  S t          || d|                    d|                     }t#          | |j                  }t'          ||          }|j        j                            | d          }|j        p,t1          t          t          j                  |j                  }|j        j                            ||t1          ||j                  |gt8          t8          g|j        |           }|}	|j	                                        5  |j        j                            |t1          ||j                  |	gt8          t8          g|j        | |          \  }
}d d d            n# 1 swxY w Y   t          |          }t?          |t@                    r-t1          t          t          j                  |j                  }	|j        j                            |t1          ||j                  |	gt8          t8          g|j        | |           |j        !                    ||j                   |j        "                    ||j        ||            t?          |t@                    rtG          |j$                  d	k     rt          t          j                  S |j$        d
         S )Nr  F)rO   rI   r   r  r   r"  r$     r   )%rF   rI   r   r   rj   r   DESCRIPTOR_SET_NOT_CALLABLEr   r*  r]   r+  valuer2   r@   r   r   rn   r   r   r   rU   r   r,  rM   r!   r   rT   r-  r   r   r.  rz   r3   r/  r0  r   r   )r  rm   r1  
dunder_setr  rv   dunder_set_typer#  rM   type_contextr   inferred_dunder_set_types               r_   r(  r(    sN   #BL11M %00;;J
8??00@@ 	
 	
 	

 y+,,,7eGG	  L $OZ_
E
EC-lC@@OF'77SSMYW(79+A#B#BBJWWWFf)??	-	4	4	4f=	'

# @  O L					 
 
&(f&9&D&DmRZ888,GgJ'' 'E '
 '
##
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  //GHH*L99 U	(> ? ?TTTF""	-	4	4	4lC	'

## #    FJ
333F((BJ'?/ )   
 />> -$.//!33y+,,,#-a00s   &AHH	Hr   r%   c                    | j         | j        j        v o-| j        j        | j                  j        | u o| j         o| j         S )z;Return if var is an instance variable according to PEP 526.)rb   r   r  r   is_classvaris_inferred)r   s    r_   is_instance_varrB  N  sN     	CHN" 	 HN38$)S0	 	  ra   r   r   r   c          	     *   |}t          ||j                  }|j        r|j        r|j        }||j        r|j        }n|j        }|rft          |t                    r'|j	        
                    ||j        ||j                  S |j        rb|j        s[|j        r-|j        s&|j                            | |j        |j                   |j        r |j                            | |j                   t%          |||||          }d}	|j        rt)          |          r|j        r{t-          |          }t          |t.                    r|                                s|}	n@|j        r7|                    ||d          }
t-          t5          d||
                    }	n|}	t          |	t.                    rH|	                                s4|j        r-|j        s&|j        s|j                            |j                   |	r|j        sg }t          |	t:                    r|	j        n|	gD ]w}t-          |          }t          |t.                    r)|                                st?          |||| ||          }nt%          |||||          }|                     |           xt;          j!        |          }nG|j        s'|j"        s |#                    |j$        |j                   tK          tL          j'                  }|j        j(         d|  }|j	        j)        *                    |          }|r-|s+|j        j+        rt)          |          stY          ||          }|r= |t[          t-          |j.                  ||j        |j        |j	                            }|S )a  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
    if is_trivial_self is True, we can use fast path for bind_self().
    NF)rS   rI   rO   __call__r   )/r   r   is_settable_propertyrO   setter_typeis_readyr   rz   r;   rU   handle_partial_var_typerT   rN   r   r]   read_only_propertyr@  cant_assign_to_classvarexpand_without_bindingis_initialized_in_classrB  rR   rF   r5   r   rn   ry   r   is_staticmethodrE   r   expand_and_bind_callabler   
make_unionrK   rh   rb   r2   r@   r   r   r   r   is_protocolr  r'   rS   )rb   r   r   rm   r   r   original_ityperv   r|   	call_typedeco_mxbound_itemsctp_ctr   r   r
  s                    r_   r   r   Z  s   $ N%eSX66E
 BL ?;3<;(Ch
 ,1c;'' 	V611#r|S"*UUU< 	A 2 	A Hs'? H))$
BJGGG A..tRZ@@@'S%LL (,	& 	 0D0D 	  	 !#&&C#|,,  S__5F5F  		  **W\*]]+,B:sT[,\,\]]			 i.. 	9y7L7L7N7N 	9| 9CO 9B<N 9,,RZ888  		7S0 		7K)3Iy)I)IZiooPY{ ) )&r**dL11 V$:J:J:L:L V3D#udBP_``DD1"c5.RTUUD""4(((()+66F| 	8BN 	8!!#(BJ777/00(#,,d,,H6=++H55D 7x 738#7 7OC<P<P 7*6266 
 01162<UWU[ 
 

 Mra   rQ  c                    t          |           } t          | |||          } t          | |          }t          |           |S r\   )r   expand_self_type_if_neededr   r*   )rv   r   r   rQ  rm   expandeds         r_   rK  rK    sF     *#
.
.C
$S"c>
B
BC&sE22H"""Ora   functypec                   t          |           } t          t          || |j                            }t	          |t
                    sJ |rt          ||j                  }nCt          ||j        |j	        |j
        ||j                  }t          ||j        |j	                  }t          ||          }t          |           |j        s|S t	          |t                     sJ |j        r|j        r|j        |j        d         S |j        S )Nr   )r   rF   r   rS   rz   r5   r   rI   r   r   rT   r]   r(   r   r*   r   r3   rE  rO   rF  r   r   )rZ  r   r   rb   rm   r   rv   rY  s           r_   rN  rN    s    /x88H
*3":JKK
L
LCc<((((( ?S",//S",0BBJPTVXV\]]R\3+=>>&sE22H"""? h-----
 !BL !S_5P!!$$  ra   tr   c                   t          |j                  }|j        sj|j        sc|j        }|rIt	          |t
                    r|j        }n,t	          |t                    rt          |j	                  }n|}t          || |          S t          t          |j                  dd          r6|j        }|rt	          |t
                    r|j        }t          || |          S |j        rY|j        |j        k    rI|j        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)rF   rI   rL   rQ   rz   rA   r   r3   r   r   r   r/   r   r   rU   scopeactive_self_type)r\  rm   r   r   r   originalrepls          r_   rX  rX    sM    r|,,HJ  "+  | 	(H-- }Hl33 %h&788Q---	%%	
 
 
  | 	!
8X66 	!=DQ---

J#("" J ,RV\224444Q
(<===ra   dispatched_arg_typer   c                   | j         }|s| S g }|rt          j        |          }|D ]}|j        r|j        d         t
          t          fvr|                    |||           | c S t          |j        d                   }	t          j
        |t          t          |	                    t          d t          |	          D                       d          r|                    |           t!          |	t"                    r|                    |           t!          |	t$                    rt&          |s!|                    |||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 type(x) <: 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.
    r   c              3  B   K   | ]}t          |t                     V  d S r\   )rz   rD   r  tvs     r_   	<genexpr>z!check_self_arg.<locals>.<genexpr>*  s@       % %8:
2{333% % % % % %ra   T)always_covariantignore_pos_arg_namesr   )r   rA   r   r   r   r   r   no_formal_selfrF   r
   
is_subtyper   r)   anyr,   r   rz   r:   rC   NotImplementedErrorincompatible_self_argumentr   r9   )
rZ  rd  r   rT   rb   r]   r   	new_itemsr   selfargs
             r_   r   r     s   " NE I L&67JKK * *~ 	*!27H:M!M!MtT7333 OOO%dnQ&788G "#~g6677 "% % %>OPW>X>X% % % " " &*	 	 	 *   &&&&G]33 *  &&&&G%566 *))* &&%uQx	
 	
 	
 
9~~|i   ra   )rt   r   r   r    Sequence[TypeVarLikeType] | Nonec          
        | j         }|r|}|j         d| }|j        j                            |          }|                    |          }	|	sk| j        r,|| j        j        v r| j        j        s| j        j        |         S |j	        s|j
        r(t          ||t          t          j                            S dS t          |	j        t"                    r*|	j        j        s|s|j                             |          rdS |j                            |	j        |j                   t          |	j        t*                    }
|
pt          |	j        t,                    }|j        ra|j        sZ|r|j                            |j                   t          |	j        t6                    r|                    t:          j                   |j        r;||j        v r2|                    t:          j         !                    |                     |	j"        rbt          |	j        t"                    rH|	j        j#        r<|                    t:          j$        !                    |	j        j%                             |j        r5|j        &                                stO          |||j        |j                   |j(        r/|j        s(|
s&|s$tS          | ||          }|rt          |||          S |	j         }|rt          |tT                    rT|	j        }t          |t"                    sJ t          |||j        +                    ||j        ||j                            S t          |	j        t*                    r|	j        j,        j-        }n0t          |	j        t"          t\          f          r|	j        j-        }nd}|sd}nt_          | |          }t          |	j        t"                    r2|J ta          |	j        j-        j1        j2                  }|	j        j        s5|	j        j-        j3        r$|4                    |	j        j-        j3                   ta          tk          |                    }||z  rht          tm          |j7                  tp                    r|	j"        r:|	j        j        rt:          j9        }nt:          j:        }|                    |           tw          |||	j        | d          }ty          t{          ||          d |D                       }|
r$t}          t*          |	j                  j?        j@        p%t          |	j        t\                    o|	j        j@        }|
r$t}          t*          |	j                  j?        jA        p%t          |	j        t\                    o|	j        jA        }tm          |          }d}t          |	j        t*                    r|	j        j?        jB        o|	j        jC         }n-t          |	j        t          t          f          r|	j        jB        }t          |t                    r'|r%|s#t          ||j3        d|j        ||j                  }t          |||||j3        ||          }|j        st          ||          }t          |||          S t          |	j        t"                    r4|J                    ||j                   t          t          j                  S t          |	j        t                    rQ|                    t:          jL        !                    |j%        |                     t          t          jM                  S t          |	j        t6                    ru|	j        jN        r$|j        jO        P                    |	j                  S |	j        j        dk    rtq          t                                S t          |	j        |jS                  S t          |	j        t                    r|S                    d	          S t          |	j        t                    r1|j        jO        V                    |	j        |j        |j        
          S |
rwt          |	j        t*                    sJ |	j        j         rt          |||	j        j                   S |J                    ||j                   t          t          jM                  S t          |	j        t\                    sJ t          |	j        |S                    d                    }|	j        j@        rt          |          }t          |||          S )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   c                    h | ]	}|j         
S rs   )idrg  s     r_   	<setcomp>z1analyze_class_attribute_access.<locals>.<setcomp>  s    C]C]C]bBEC]C]C]ra   F)r   r   ztypes.NoneTypeztypes.ModuleTyper   r   )Yr   r   rU   r   get_class_attribute_hookr   r   r   r   r   meta_fallback_to_anyapply_class_attr_hookr2   r@   r   rz   r   r%   r@  r   rT   r   r   rO   rN   r]   r   r#   rj   r   CANNOT_ASSIGN_TO_TYPEslotsCLASS_VAR_CONFLICTS_SLOTSr   r   r   !CANNOT_ACCESS_FINAL_INSTANCE_ATTRrb   r   r   is_enum#analyze_enum_class_attribute_accessr;   rH  r   r   r   r   setr   	type_varsrI   r   r-   rF   rS   rA   GENERIC_CLASS_VAR_ACCESS!GENERIC_INSTANCE_VAR_CLASS_ACCESSrX  r   r   r   r   r   r   r   r   r   r   r5   r   add_class_tvarsr  rh   r$    CANNOT_USE_TYPEVAR_AS_EXPRESSIONr   typeddict_typer   typeddict_callabler8   r1   re   r   r"   r   r+   r   )r   rb   rm   r   rt   r   r   r   r
  r   is_decorated	is_methodenum_class_attribute_typer\  symnode
super_infoisuperdef_varstyp_varsmessager   rM  r   r|   rv   s                            r_   r   r   @  s    :D -(($((H6=11(;;D88D>>D  	5):)@!@!@$- 5(.t44 	T4#< 	T(T79;Q3R3RSSSt 	49c""	%  !!$''	 tF49bj111di33L?
49h ? ?I	| <B. < 	5F((444di** 	<GG$:;;; z Iddj((
 :AA$GGHHH } [DIs33 [	8J [
 BII$).YYZZZ 
| ;BF4466 ;4rvrz:::| NR\ N\ NY N$GtUW$X$X!$ 	N(T3LMMM	A U/a%% 	iGgs+++++(D"&88BL'SUS]^^  
 di++ 	*.)-*<JJ	C)>#?@@ 	JJJ  	BFF.ujAAFdi%% 	_%%% 49>.899H9( 7TY^-E 7TY^5666=++,,H(" %!/"2B"C"CXNN %RVR_ %y, U"2"K"2"TGGG$$$*1b$)UTRRRA
 6q&AAC]C]T\C]C]C]^^A&S4	49+E+E+J+S 
ty"788OTY=O 	 (UDDI,F,F,K,U 
ty"788PTY=P 	 Adi++ 	8"in<YTYEYAYOO	G->#?@@ 	8"i7Oa&& 	Q> 	Q/ 	Qq",rz4PPA L'+
 
 
 | 	;.vr::F$Rv666	DIs	#	# /
dBJ///y-...$)[)) -
 AHHTXYYZZZy+,,, $)X&& >9# 	>6&99$)DDDY#333HJJ'''#DIr}===$)X&& 1}}/000$)Y'' 
v"@@I2: A 
 
 	
  4$)Y/////9> 	1(T49>BBB!!$
3339/000$)%:;;;;;DIr}}5H'I'IJJ 9 	& %%C$Rs333ra   r
  )Callable[[AttributeContext], Type] | Noner|   c           	         |r= |t          t          | j                  || j        | j        | j                            }|S r\   )r'   rF   rS   rO   rT   rU   )rm   r
  r|   s      r_   rz  rz    sO      
 01162<UWU[ 
 

 Mra   c                   |t           v rt          |j        | ||          S |                    d          r|                    dd          dk    rd S | j                            |          }|rT|j        rMt          |j                  }t          |t                    r$|j        j
        dk    r|j        r|j        d         S t          ||           }|                     |          S )N__r    zenum.nonmemberr   r   )r{   )r   r   rS   
startswithreplacer   r   rF   rz   r6   r   argsr7   rn   )r   rb   rm   r   properenum_literals         r_   r  r    s     ''''(8%rJJJt c2!6!6"!<!<t:>>$D "	 " ++ vx((	"$(888 9 ;q>!te444L===ra   r?   c           	        | dk    rt          |j        t                    rd|j        j                            ||j        j        d          \  }}|j        |z  }|r(|j        s!|j	        
                    ||j                   nt          t          j                  }t          |j                            d          |gt           t           gd d gt#                      |j                            d          |           S | dk    rYt          |j                            d          gt           gd gt#                      |j                            d          |           S t%          | |j        ||          S )	N__setitem__T)setitemr  zbuiltins.strr   )r   r   r   r   r   rb   __delitem__)rz   rT   r   rU   r   visit_typeddict_index_exprindexreadonly_keysrN   r]   readonly_keys_mutatedr2   r@   implementation_artifactr3   re   r   r8   ry   r   )rb   rv   rm   rt   	item_type	key_namesassigned_readonly_keyss          r_   r   r   4  s    }bj),, 	C $&6#6#Q#QRZ%t $R $ $ Iy &)%6%B"% Yb.@ Y,,-CRZ,XXX  	 ABBIv((88)D(TlZZV&&':;;
 
 
 	
 
		v((889ifZZV&&':;;
 
 
 	
 "$b-HHHra   r<   r  Instance | NonerM  c                   t          | t                    rng }t          |           } r%|rt          |           } nt	          | d          } srJ t          |           } t          |            |                     t          |          t          | j	                  z             S t          | t                    r$t          fd| j        D                       S t          |           } | S )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
        is_trivial_self: if True, we can use fast path for bind_self().
    Returns:
        Expanded method type with added type variables (when needed).
    NTr   )r   c                `    g | ]*}t          t          t          |                     +S ))r   )r   r3   r  )r  r   r   rM  r  rS   r   s     r_   r  z#add_class_tvars.<locals>.<listcomp>  s\          #&'%&3  
 
  ra   )rz   r3   r   r   r(   r   r*   rn   listr   r9   r   )r\  r  r   rM  rS   r   r   tvarss    `````  r_   r  r  [  sM   \ !\"" 
!.!:+A.. 	E E"1m44atDDD 	3_ 	3%%%'622AQetAK7H7H)HIII	Az	"	" 
        G  
 
 	
  #Av..Hra   r   Decorator | FuncBasec                   t          | t                    rt          || j        ||          S t	          | |j                            d                    }d}t          | t                    r| j        j        o| j	         }n#t          | t          t          f          r| j        }|rt          ||j                  S t          ||j        | j        |j        ||j                  }t%          ||j        | j                  S )zAnalyzes the type behind method access.

    The function itself can possibly be decorated.
    See: https://github.com/python/mypy/issues/10409
    r   F)rS   r   )rz   r   r   r   r+   rU   re   r   r   r   r   r   r   rI   r   r   rT   r]   r(   )r   r   rb   rm   rv   r   s         r_   r   r     s     $	"" 645"555
bf//0CDD
E
ECO$	"" /)3KDO8K	D7$56	7	7 /. 1c2<000
blDM2:tRV
T
TCST]SSSSra   F)boundr   c                   t          | t                    r5fd| j        D             }t          t          t          |                    S t          | t
                    sJ | j        st          t          |           S | j        d         t          t          fv rt          t          |           S t                    t          t
                    r-                                rt          j        j                  |                     | j        dd         | j        dd         | j        dd         g          }t          t          |          S )zReturn a copy of `method`, with the type of its first parameter (usually
    self or cls) bound to original_type.

    This is a faster version of mypy.typeops.bind_self() that can be used for methods
    with trivial self/cls annotations.
    c                0    g | ]}t          |          S rs   )r   )r  crS   s     r_   r  z"bind_self_fast.<locals>.<listcomp>  s#    HHHa=11HHHra   r   r   N)r   r   r   
bound_args)rz   r9   r   r   r  r3   r   r   r   r   rF   r   rA   r   r   rn   r   )r   rS   r   ress    `  r_   r   r     sB    &*%% *HHHH6<HHHAz%(()))fl+++++ Avx333Av#M22M-.. I=3L3L3N3N I 01GHH


"122&"122&"122&!?	   C 3<<ra   )"rb   rc   rv   r>   rT   r   rO   rP   rQ   rP   rR   rP   rS   r>   rU   r   rt   rw   ru   rP   rI   rV   rJ   rW   rK   rP   rL   rP   rM   rX   rN   rP   rY   r>   r\   )
rb   rc   rv   r>   rm   rH   rt   rw   rY   r>   )
rb   rc   rv   r>   rm   rH   rt   rw   rY   rP   )rS   r>   rv   r>   rb   rc   rm   rH   rt   rw   rY   r>   )
rb   rc   rv   r6   rm   rH   rt   rw   rY   r>   )r   r   rm   rH   rY   rZ   )rb   rc   rv   r5   rm   rH   rY   r>   )
rb   rc   rv   rA   rm   rH   rt   rw   rY   r>   )rb   rc   rv   rE   rm   rH   rY   r>   )rb   rc   rv   r8   rm   rH   rY   r>   )
rb   rc   r   r6   r   r#   rm   rH   rY   r>   )
rb   rc   r   r#   r]   r   r   r   rY   rZ   )r  r>   rm   rH   rY   r>   )r  r6   rm   rH   rY   r>   )r   r%   rY   rP   )rb   rc   r   r%   r   r6   rm   rH   r   rP   r   rP   rY   r>   )rv   r>   r   r%   r   r6   rQ  r6   rm   rH   rY   r>   )rZ  r5   r   r%   r   r6   rb   rc   rm   rH   r   rP   rY   r>   )F)r\  r>   rm   rH   r   r%   r   r6   r   rP   rY   r>   )rZ  r5   rd  r>   r   rP   rT   r   rb   rc   r]   r   rY   r5   )r   r6   rb   rc   rm   rH   r   r6   rt   rw   r   rs  rY   rV   )rm   rH   r
  r  r|   r>   rY   rV   )r   r6   rb   rc   rm   rH   rY   rV   )
rb   rc   rv   r?   rm   rH   rt   rw   rY   r>   )NF)r\  r<   r  r  r   rP   rM  rP   rS   r>   r   rs  r   rP   rY   r>   )
r   r  r   r6   rb   rc   rm   rH   rY   r>   )r   r  rS   rV   rY   r  )orr   
__future__r   collections.abcr   typingr   r   r   mypyr   r	   r
   mypy.checker_sharedr   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/   r0   r1   
mypy.typesr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rH   r~   ry   r   r   r   r   r   r   r   r   r   r   r  r(  rB  r   rK  rN  rX  r   r   rz  r  r   r  r   r  r   rs   ra   r_   <module>r     s   ' ' " " " " " " $ $ $ $ $ $ * * * * * * * * * * 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 4 ) ) ) ) ) )         
 3 2 2 2 2 2 ( ( ( ( ( (                                             . ) ( ( ( ( (                                                                    2J J J J J J J Jn &*$!.2 $!#I I I I I IZ OS%E %E %E %E %ER OS1 1 1 1 1, &*) ) ) ) )(E> E> E> E>PC C C C!6 !6 !6 !6H5I 5I 5I 5Ip* * * *R R R RL L L L^F F F Fl- l- l- l-^E1 E1 E1 E1P	 	 	 	$ !R R R R R Rj   ! ! ! !< MR) ) ) ) )X;! ;! ;! ;!H &*6:L4 L4 L4 L4 L4 L4^	 	 	 	> > > >2$I $I $I $IZ 7;!N N N N NbT T T T. GC|$$$      ra   