
    X-Ph7                       d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	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mZmZ d dl m!Z!m"Z"m#Z#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/m0Z0m1Z1m2Z2m3Z3 d d
l4m5Z5 d dl6m7Z7 d dl8m9Z9 dPdZ:dQdZ;dRdZ<dSdZ=dTd Z>	 	 	 	 dUdVd.Z? G d/ d0e          Z@	 	 	 	 dUdWd7ZA	 	 dXdYd;ZBdZd<ZCd[dAZD	 	 	 	 	 	 d\d]dLZEd^dOZFd!S )_    )annotations)
NamedTuple)map_actuals_to_formals)	TypeFixer)ARG_POSMDEFSYMBOL_FUNCBASE_TYPESArgumentBlockCallExprClassDef	Decorator
ExpressionFuncDefJsonDictNameExprNodeOverloadedFuncDefPassStmtRefExprSymbolTableNodeTypeInfoVar)CheckerPluginInterfaceClassDefContextSemanticAnalyzerPluginInterface)ALLOW_INCOMPATIBLE_OVERRIDE
parse_boolrequire_bool_literal_argumentset_callable_name)try_getting_str_literals)AnyTypeCallableTypeInstanceLiteralTypeNoneType
OverloadedType	TypeOfAnyTypeTypeTypeVarTypedeserialize_typeget_proper_type)is_overlapping_none)fill_typevars)get_unique_redefinition_namectxr   namestrdefaultboolreturnc                h    t          | j        t                    rt          | | j        ||          S |S )zgReturn the bool argument for the decorator.

    This handles both @decorator(...) and @decorator.
    )
isinstancereasonr   _get_bool_argument)r1   r2   r4   s      S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/plugins/common.py_get_decorator_bool_argumentr<   7   s3    
 #*h'' !#sz4AAA    exprr   c                X    t          ||          }|rt          | j        |||          S |S )z]Return the boolean value for an argument to a call or the
    default if it's not found.
    )_get_argumentr   api)r1   r>   r2   r4   
attr_values        r;   r:   r:   B   s7     tT**J Q,SWj$PPPNr=   callExpression | Nonec                   t          |           }|sdS |                    |          }|sdS |j        sJ t          t	          | j        | j                            D ]/\  }\  }}|j        |s||j        k    r|c S ||j        k    r|c S 0dS )z0Return the expression for the specific argument.N)_get_callee_typeargument_by_namer2   	enumeratezip	arg_namesargspos)rC   r2   callee_typeargumenti	attr_namerB   s          r;   r@   r@   L   s     #4((K t++D11H t=&/DNDI0N0N&O&O  ""Iz<#I#!x|:K:K%% & 4r=   overloadr'   r#   c           	       	
 | j         dd         D ]}d}t          j        j        |j        |j        d           }t	                      
|D ]}
                    |           t          
fdt          t          j	                            D                       rd}t          |j        |j        |          D ]\  	}}|                                r|sd} n|rfd|D             }t          	          	t          d |D                       }t          	t                    r|sd} nu|rMt!          	          s>t          	t"                    r	j        j        d	k    st          	t(                    sd} nPt          	t*                    r9t          	j        t.                    rt          	fd
|D                       sd} n|r|c S | j         d         S )aT  Perform limited lookup of a matching overload item.

    Full overload resolution is only supported during type checking, but plugins
    sometimes need to resolve overloads. This can be used in some such use cases.

    Resolve overloads based on these things only:

    * Match using argument kinds and names
    * If formal argument has type None, only accept the "None" expression in the callee
    * If formal argument has type Literal[True] or Literal[False], only accept the
      relevant bool literal

    Return the first matching overload item, or the last one if nothing matches.
    NTc                4    t          t          j                  S N)r"   r)   special_form)rO   s    r;   <lambda>z5find_shallow_matching_overload_item.<locals>.<lambda>{   s    gi455 r=   c              3      K   | ]}|vV  	d S rU    ).0rO   matched_actualss     r;   	<genexpr>z6find_shallow_matching_overload_item.<locals>.<genexpr>   s(      GGAq'GGGGGGr=   Fc                *    g | ]}j         |         S rY   )rK   )rZ   rO   rC   s     r;   
<listcomp>z7find_shallow_matching_overload_item.<locals>.<listcomp>   s    666	!666r=   c              3  V   K   | ]$}t          |t                    o
|j        d k    V  %dS )NoneN)r8   r   r2   )rZ   args     r;   r\   z6find_shallow_matching_overload_item.<locals>.<genexpr>   s9      ``TWz#x88OSX=O``````r=   zbuiltins.objectc              3  H   K   | ]}t          |          j        k    V  d S rU   )r   value)rZ   ra   arg_types     r;   r\   z6find_shallow_matching_overload_item.<locals>.<genexpr>   s0      QQSz#(.@QQQQQQr=   )itemsr   	arg_kindsrJ   setupdateanyrangelenrK   rI   	arg_typesis_requiredr-   r8   r&   r.   r$   typefullnamer"   r%   rc   r5   )rQ   rC   itemokmappedactualskindrK   arg_nonerd   r[   s    `       @@r;   #find_shallow_matching_overload_itemrv   e   sR    ss# . .'NNNN55
 
 %% 	, 	,G""7++++GGGGs49~~1F1FGGGGG 	B'*4>4>6'R'R 	 	#HdG!! '  6666g666*844``[_`````h11 # " /99 #8X66	
 %M26GGG&x99 H BE+66 :hnVZ;[;[ QQQQDQQQQQ " 	KKK	>"r=   CallableType | Nonec                j   | j         }t          |t                    r|j        }t          |t                    r|j        }t          |t          t          f          rW|j        rPt          |j                  }t          |t                    rt          ||           S t          |t                    r|S dS )z@Return the type of the callee, regardless of its syntactic form.N)calleer8   r   noder   funcr   r	   rn   r-   r'   rv   r#   )rC   callee_nodecallee_node_types      r;   rF   rF      s      ${K+w'' '!& +y)) '!&+%:;<< $AQ $*;+;<<&
33 	$67GNNN(,77 	$##4r=   NFrK   list[Argument]return_typer(   	self_typeType | Nonetvar_defTypeVarType | Noneis_classmethodis_staticmethodr`   c                J    t          | j        | j        |||||||	  	         dS )zZ
    Adds a new method to a class.
    Deprecated, use add_method_to_class() instead.
    )r2   rK   r   r   r   r   r   N)add_method_to_classrA   cls)r1   r2   rK   r   r   r   r   r   s           r;   
add_methodr      sD     %'
 
 
 
 
 
r=   c                  D    e Zd ZU dZded<   ded<   dZded<   dZd	ed
<   dS )
MethodSpecz=Represents a method signature to be added, except for `name`.r~   rK   r(   r   Nr   r   zlist[TypeVarType] | None	tvar_defs)__name__
__module____qualname____doc____annotations__r   r   rY   r=   r;   r   r      sR         GG!I!!!!*.I......r=   r   rA   8SemanticAnalyzerPluginInterface | CheckerPluginInterfacer   r   &list[TypeVarType] | TypeVarType | NoneFuncDef | Decoratorc	                &   t          ||           |t          |t                    s|g}t          | |j        |t          ||||          ||          \  }	}
|
|j        j        |<   |j        j        j        j	        
                    |	           |	S )z(Adds a new method to a class definition.N)rK   r   r   r   )r   r   )_prepare_class_namespacer8   list_add_method_by_specinfor   namesdefndefsbodyappend)rA   r   r2   rK   r   r   r   r   r   r{   syms              r;   r   r      s     S$'''Jx$>$>:#+V^___%'  ID# CHN4HM""4(((Kr=   re   list[MethodSpec]r   c           	        t          |          dk    s
J d            t          ||           g }|D ]}t          | |j        ||||          \  }}	t	          |t
                    rMt          |j        |j                  }
|
	                    |j
                   d|_        t          |g |
          }n|}d|_        |                    |           t          |          }|j        |_        ||_        ||_        t%          t&          |          }d|_        ||j        j        |<   |j        j        j        j                            |           |S )z3Adds a new overloaded method to a class definition.   z)Overloads must contain at least two cases)r2   specr   r   T)rk   r   r   r   r8   r   r   r2   rn   set_linelineis_decoratedr   is_overloadr   r   is_class	is_staticr   r   plugin_generatedr   r   r   r   )rA   r   r2   re   r   r   funcsrp   r{   _symvardecooverload_defr   s                 r;   add_overloaded_method_to_classr      s\    u::???G??? S$''' (*E  (H)+
 
 

d dG$$ 	di++CLL### $DT2s++DDDT %U++LL*L,L
$
-
-CCCHN4HM""<000r=   c                <   | j         }|sJ ||j        v rR|j        |         }|j        r>t          |j        t
                    r$| j        j                            |j                   ||j        v r,t          ||j                  }|j        |         |j        |<   d S d S rU   )
r   r   r   r8   rz   r   r   r   remover0   )r   r2   r   r   r_names        r;   r   r   1  s    8DKKK tzj 	+Jsx$A$A 	+HM  *** tz-dDJ??!Z-
6 r=   r   r   r   +tuple[FuncDef | Decorator, SymbolTableNode]c                  |\  }}}}	|du r|du r
J d            t          | t                    r|                     d          }
n|                     dg           }
|rE|pt	          t          |                    }t          t          d          |d t          d          g}n;|rg }n6|pt          |          }t          t          d          |d t                    g}||z   }g g g }}}|D ]f}|j	        s
J d            |
                    |j	                   |
                    |j        j                   |
                    |j                   gt          |||||
          }|	r|	|_        t!          ||t#          t%                      g                    }||_        t)          ||          |_        ||_        ||_        |j        dz   |z   |_        |j        |_        |rsd|_        t          ||j                  }||_        |j        |_        d|_        t;          |g |          }|j        |_        t=          t>          |          }d|_         ||fS t=          t>          |          }d|_         ||fS )NTz@Can't add a new method that's both staticmethod and classmethod.zbuiltins.function_clsselfz"All arguments must be fully typed..)!r8   r   
named_typenamed_generic_typer*   r/   r
   r   r   type_annotationr   variabler2   rt   r#   	variablesr   r   r   r   r    rn   r   r   ro   	_fullnamer   r   r   r   r   r   r   )rA   r   r2   r   r   r   rK   r   r   r   function_typefirstrl   rJ   rf   ra   	signaturer{   vdecr   s                        r;   r   r   D  s    /3+D+y) 	$?d#:#:#:I $;#:#: #677 H':;;../BBGG B>-*=*=!>!>	#f++y$FFG	 B4t!4!4	#f++y$@@A4<D&("b)yI # #"HH$HHHH,---*+++""""Y	9k=YYI ('	4uhjj\2233DDI!)T22DI"DM$DN]S(4/DN	DI  
 di  n b!$$9dC((#Cx
$
%
%CC9r=   r   typfinalno_serializeoverride_allow_incompatiblero   
str | Noneis_classvaroverwrite_existingr   c
                p   |j         }
||
j        v r,|	s*t          ||
j                  }|
j        |         |
j        |<   t          ||          }|
|_         ||_        ||_        |t          v rd|_        n||_        |r||_        n|
j	        dz   |z   |_        t          t          |d|          |
j        |<   |S )z
    Adds a new attribute to a class definition.
    This currently only generates the symbol table entry and no corresponding AssignmentStatement
    Tr   )r   r   )r   r   r0   r   is_finalr   r   allow_incompatible_overrider   ro   r   r   )rA   r   r2   r   r   r   r   ro   r   r   r   r   rz   s                r;   add_attribute_to_classr     s      8D tz"4-dDJ??!Z-
6tS>>DDIDM"D***+/((+F( 4!,t3&dT  DJt Kr=   datastr | JsonDictc                v    t          |           }|                    t          |j        d                     |S )NF)allow_missing)r,   acceptr   modules)r   rA   r   s      r;   deserialize_and_fixup_typer     s5    
4
 
 CJJyE:::;;;Jr=   )r1   r   r2   r3   r4   r5   r6   r5   )
r1   r   r>   r   r2   r3   r4   r5   r6   r5   )rC   r   r2   r3   r6   rD   )rQ   r'   rC   r   r6   r#   )rC   r   r6   rw   )NNFF)r1   r   r2   r3   rK   r~   r   r(   r   r   r   r   r   r5   r   r5   r6   r`   )rA   r   r   r   r2   r3   rK   r~   r   r(   r   r   r   r   r   r5   r   r5   r6   r   )FF)rA   r   r   r   r2   r3   re   r   r   r5   r   r5   r6   r   )r   r   r2   r3   r6   r`   )rA   r   r   r   r2   r3   r   r   r   r5   r   r5   r6   r   )FFFNFF)rA   r   r   r   r2   r3   r   r(   r   r5   r   r5   r   r5   ro   r   r   r5   r   r5   r6   r   )r   r   rA   r   r6   r(   )G
__future__r   typingr   mypy.argmapr   
mypy.fixupr   
mypy.nodesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.pluginr   r   r   mypy.semanal_sharedr   r   r   r    mypy.typeopsr!   
mypy.typesr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   mypy.types_utilsr.   mypy.typevarsr/   	mypy.utilr0   r<   r:   r@   rv   rF   r   r   r   r   r   r   r   r   rY   r=   r;   <module>r      s   " " " " " "       . . . . . .                                                     * a ` ` ` ` ` ` ` ` `            N M M M M M                            1 0 0 0 0 0 ' ' ' ' ' ' 2 2 2 2 2 2         2> > > >B   8 "#' !    6/ / / / / / / /  "7; !    H !!. . . . .b. . . .&@ @ @ @P (-$* * * * *Z     r=   