
    X-Ph<                    V   U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlmZ ddlmZ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 ddl m!Z! dd	l"m#Z# dd
l$m%Z%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: dZ;de<d<   dZ=de<d<   e G d d                      Z>e G d de>                      Z?dHdZ@dId ZA G d! d"e	          ZBd#d#d$d%dJd2ZCd#d#d$d%dJd3ZD G d4 d5e&          ZEdKd7ZFdLd;ZGe
dMdB            ZHe
	 dNdOdD            ZH	 dNdPdEZHdQdGZId$S )Rz@Shared definitions used by different parts of semantic analysis.    )annotations)abstractmethod)CallableFinalLiteralProtocoloverload)trait)LITERAL_REQ	ErrorCode)CallExprClassDefContextDataclassTransformSpec	Decorator
ExpressionFuncDefNameExprNodeOverloadedFuncDefRefExpr
SymbolNodeSymbolTableSymbolTableNodeTypeInfo)SemanticAnalyzerPluginInterface)TypeVarLikeScope)ANY_STRATEGYBoolTypeQuery)make_simplified_union)TPDICT_FB_NAMESAnyTypeFunctionLikeInstance
ParametersParamSpecFlavorParamSpecTypePlaceholderType
ProperType	TupleTypeType	TypeOfAny	TypeVarIdTypeVarLikeTypeTypeVarTupleType
UnpackTypeget_proper_type)	__slots____deletable____match_args__r   ALLOW_INCOMPATIBLE_OVERRIDE   PRIORITY_FALLBACKSc                     e Zd ZdZe	 d*d+d            Zed,d            Zed-d            Ze	 d*dddd.d            Zeddd/d            Z	ed0d            Z
ed1d            Zed2d3d!            Zed4d"            Zeed5d#                        Zed6d%            Zeed5d&                        Zed5d'            Zeed7d)                        ZdS )8SemanticAnalyzerCoreInterfacezA core abstract interface to generic semantic analyzer functionality.

    This is implemented by both semantic analyzer passes 2 and 3.
    Fnamestrctxr   suppress_errorsboolreturnSymbolTableNode | Nonec                    t           NNotImplementedErrorselfr:   r<   r=   s       S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/semanal_shared.pylookup_qualifiedz.SemanticAnalyzerCoreInterface.lookup_qualifiedG   
     "!    fullnamer   c                   t           rB   rC   rF   rK   s     rG   lookup_fully_qualifiedz4SemanticAnalyzerCoreInterface.lookup_fully_qualifiedM       !!rJ   c                   t           rB   rC   rM   s     rG   lookup_fully_qualified_or_nonez<SemanticAnalyzerCoreInterface.lookup_fully_qualified_or_noneQ   rO   rJ   N)blockercodemsgseriousrR   rS   ErrorCode | NoneNonec                   t           rB   rC   )rF   rT   r<   rU   rR   rS   s         rG   failz"SemanticAnalyzerCoreInterface.failU   s
     "!rJ   rS   c                   t           rB   rC   )rF   rT   r<   rS   s       rG   notez"SemanticAnalyzerCoreInterface.notea   rO   rJ   featurec                    t           rB   rC   )rF   r]   r<   s      rG   incomplete_feature_enabledz8SemanticAnalyzerCoreInterface.incomplete_feature_enablede   rO   rJ   c                    t           rB   rC   rF   s    rG   record_incomplete_refz3SemanticAnalyzerCoreInterface.record_incomplete_refi   rO   rJ   debug_contextContext | Noneforce_progressc                    t           rB   rC   )rF   rc   re   s      rG   deferz#SemanticAnalyzerCoreInterface.deferm   rO   rJ   c                    t           )zDIs a module or class namespace potentially missing some definitions?rC   rM   s     rG   is_incomplete_namespacez5SemanticAnalyzerCoreInterface.is_incomplete_namespaceq   
     "!rJ   c                    t           )z1Is this the final iteration of semantic analysis?rC   ra   s    rG   final_iterationz-SemanticAnalyzerCoreInterface.final_iterationv   rI   rJ   flagc                    t           )z+Is the specific __future__ feature importedrC   )rF   rm   s     rG   is_future_flag_setz0SemanticAnalyzerCoreInterface.is_future_flag_set|   rj   rJ   c                    t           rB   rC   ra   s    rG   is_stub_filez*SemanticAnalyzerCoreInterface.is_stub_file   rj   rJ   c                    t           rB   rC   ra   s    rG   is_func_scopez+SemanticAnalyzerCoreInterface.is_func_scope   rO   rJ   TypeInfo | Nonec                    t           rB   rC   ra   s    rG   typez"SemanticAnalyzerCoreInterface.type   rj   rJ   Fr:   r;   r<   r   r=   r>   r?   r@   )rK   r;   r?   r   )rK   r;   r?   r@   )rT   r;   r<   r   rU   r>   rR   r>   rS   rV   r?   rW   )rT   r;   r<   r   rS   rV   r?   rW   )r]   r;   r<   r   r?   r>   r?   rW   )NF)rc   rd   re   r>   r?   rW   )rK   r;   r?   r>   r?   r>   )rm   r;   r?   r>   )r?   rt   )__name__
__module____qualname____doc__r   rH   rN   rQ   rY   r\   r_   rb   rg   ri   propertyrl   ro   rq   rs   rv    rJ   rG   r9   r9   @   s2        
 ?D" " " " ^"
 " " " ^" " " " ^" 
 		" !%	" 	" 	" 	" 	" ^	" GK " " " " " ^" " " " ^" " " " ^" " " " " ^" " " " ^" " " " ^ X" " " " ^" " " " ^ X" " " " ^" " " " ^ X" " "rJ   r9   c            
         e Zd ZU dZded<   e	 dKdLd            ZedMdNd            ZedMdOd            ZedPd            Z	eddddddddddQd(            Z
edRd,            ZedSd1            ZedTd5            ZedUd8            ZedVd:            Ze	 	 	 dWdXd@            ZedYdA            ZedZdE            Zed[dF            Zeed\dG                        Ze	 dKd]dJ            ZdS )^SemanticAnalyzerInterfacezA limited abstract interface to some generic semantic analyzer pass 2 functionality.

    We use this interface for various reasons:

    * Looser coupling
    * Cleaner import graph
    * Less need to pass around callback functions
    r   
tvar_scopeFr:   r;   r<   r   r=   r>   r?   r@   c                    t           rB   rC   rE   s       rG   lookupz SemanticAnalyzerInterface.lookup   rI   rJ   NrK   argslist[Type] | Noner$   c                    t           rB   rC   rF   rK   r   s      rG   
named_typez$SemanticAnalyzerInterface.named_type   rO   rJ   Instance | Nonec                    t           rB   rC   r   s      rG   named_type_or_nonez,SemanticAnalyzerInterface.named_type_or_none   rO   rJ   noder   rW   c                    t           rB   rC   )rF   r   s     rG   acceptz SemanticAnalyzerInterface.accept   rO   rJ   T)r   allow_tuple_literalallow_unbound_tvarsallow_typed_dict_special_formsallow_placeholderreport_invalid_typesprohibit_self_type"prohibit_special_class_field_typestypr+   TypeVarLikeScope | Noner   r   r   r   r   r   
str | Noner   Type | Nonec                  t           rB   rC   )
rF   r   r   r   r   r   r   r   r   r   s
             rG   	anal_typez#SemanticAnalyzerInterface.anal_type   s
     "!rJ   
type_exprslist[Expression]list[TypeVarLikeType]c                    t           rB   rC   )rF   r   s     rG   get_and_bind_all_tvarsz0SemanticAnalyzerInterface.get_and_bind_all_tvars   rO   rJ   basetype_or_fallbacklineintr   c                    t           rB   rC   )rF   r:   r   r   s       rG   basic_new_typeinfoz,SemanticAnalyzerInterface.basic_new_typeinfo   rO   rJ   prioritypatchCallable[[], None]c                    t           rB   rC   )rF   r   r   s      rG   schedule_patchz(SemanticAnalyzerInterface.schedule_patch   rO   rJ   symbolr   c                    t           )z%Add node to the current symbol table.rC   )rF   r:   r   s      rG   add_symbol_table_nodez/SemanticAnalyzerInterface.add_symbol_table_node   rj   rJ   r   c                    t           )z^Get currently active symbol table.

        May be module, class, or local namespace.
        rC   ra   s    rG   current_symbol_tablez.SemanticAnalyzerInterface.current_symbol_table   s
     "!rJ   r   contextmodule_publicmodule_hidden	can_deferc                    t           )z'Add symbol to the current symbol table.rC   )rF   r:   r   r   r   r   r   s          rG   
add_symbolz$SemanticAnalyzerInterface.add_symbol   s
     "!rJ   c                    t           )a  Add symbol to the current symbol table, skipping locals.

        This is used to store symbol nodes in a symbol table that
        is going to be serialized (local namespaces are not serialized).
        See implementation docstring for more details.
        rC   )rF   r:   r   s      rG   add_symbol_skip_localz/SemanticAnalyzerInterface.add_symbol_skip_local   s
     "!rJ   exprr   bool | Nonec                    t           rB   rC   )rF   r   s     rG   
parse_boolz$SemanticAnalyzerInterface.parse_bool   rO   rJ   c                    t           rB   rC   )rF   r:   s     rG   qualified_namez(SemanticAnalyzerInterface.qualified_name   rO   rJ   c                    t           rB   rC   ra   s    rG   is_typeshed_stub_filez/SemanticAnalyzerInterface.is_typeshed_stub_file   rj   rJ   kindre   c                    t           rB   rC   )rF   r:   r   r<   re   s        rG   process_placeholderz-SemanticAnalyzerInterface.process_placeholder   rI   rJ   rw   rx   rB   rK   r;   r   r   r?   r$   )rK   r;   r   r   r?   r   )r   r   r?   rW   )r   r+   r   r   r   r>   r   r>   r   r>   r   r>   r   r>   r   r   r   r   r?   r   )r   r   r?   r   )r:   r;   r   r$   r   r   r?   r   )r   r   r   r   r?   rW   )r:   r;   r   r   r?   r>   )r?   r   )TFT)r:   r;   r   r   r   r   r   r>   r   r>   r   r>   r?   r>   )r:   r;   r   r   r?   rW   r   r   r?   r   )r:   r;   r?   r;   rz   )
r:   r   r   r;   r<   r   re   r>   r?   rW   )r{   r|   r}   r~   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rJ   rG   r   r      s          !   ?D" " " " ^"
 " " " " ^" " " " " ^" " " " ^"  /3$)$)/4"'%))-9=" " " " " ^"  " " " ^" " " " ^" " " " ^" " " " ^" " " " ^"  ##
" 
" 
" 
" ^
" " " " ^" " " " ^" " " " ^" " " " ^ X" PU" " " " ^" " "rJ   r   sigr+   fdefr   r?   r)   c                   t          |           } t          | t                    rb|j        rA|j        j        t
          v rd}n|j        j        }|                     |j         d|           S |                     |j                  S | S )N	TypedDictz of )r1   
isinstancer#   inforK   r!   r:   	with_name)r   r   
class_names      rG   set_callable_namer     s    
#

C#|$$ 9 	,y!_44(

!Y^
==DI!?!?:!?!?@@@==+++
rJ   r   r*   rW   c                   | j         }|j        j        dk    sJ g }| j        D ]}t	          |t
                    rt          |j                  }t	          |t                    rt          |j                  }t	          |t                    r1|j        j        dk    r!|
                    |j        d                    t          |
                    |           t          |          f|_        dS )a  Calculate a precise item type for the fallback of a tuple type.

    This must be called only after the main semantic analysis pass, since joins
    aren't available before that.

    Note that there is an apparent chicken and egg problem with respect
    to verifying type arguments against bounds. Verifying bounds might
    require fallbacks, but we might use the bounds to calculate the
    fallbacks. In practice this is not a problem, since the worst that
    can happen is that we have invalid type argument values, and these
    can happen in later stages as well (they will generate errors, but
    we don't prevent their existence).
    builtins.tupler   N)partial_fallbackrv   rK   itemsr   r0   r1   r/   upper_boundr$   appendr   rD   r    )r   fallbackr   itemunpacked_types        rG   calculate_tuple_fallbackr     s     #H=!%55555E	  dJ'' 	+DI66M-)9:: K /0I J J=(33*!&/3CCC]/23333))LL*5113HMMMrJ   c                      e Zd Zd	d
dZdS )_NamedTypeCallbackNrK   r;   r   r   r?   r$   c                    d S rB   r   r   s      rG   __call__z_NamedTypeCallback.__call__8  s      rJ   rB   r   )r{   r|   r}   r   r   rJ   rG   r   r   7  s        VVVVVVVrJ   r   N)r   columnprefixr:   r;   rK   idr-   named_type_funcr   r   r   r   Parameters | Noner'   c                   t          | ||t          j         |d |d          g          t          t          j                  |||	  	        S )Nr   builtins.objectflavorr   defaultr   r   r   )r'   r&   ARGSr"   r,   from_omitted_genericsr:   rK   r   r   r   r   r   s          rG   paramspec_argsr   ;  s_     
##O$4GX7Y7Y6Z[[	788
 
 
 
rJ   c                   t          | ||t          j         |d |d           |d          g          t          t          j                  |||	  	        S )Nzbuiltins.dictzbuiltins.strr   r   )r'   r&   KWARGSr"   r,   r   r   s          rG   paramspec_kwargsr   R  sq     
%#Ooon==O`?a?ab
 
 	788   rJ   c                  (     e Zd Zd fdZd	dZ xZS )
HasPlaceholdersr?   rW   c                T    t                                          t                     d S rB   )super__init__r   )rF   	__class__s    rG   r   zHasPlaceholders.__init__l  s!    &&&&&rJ   tr(   r>   c                    dS )NTr   )rF   r   s     rG   visit_placeholder_typez&HasPlaceholders.visit_placeholder_typeo  s    trJ   ry   )r   r(   r?   r>   )r{   r|   r}   r   r   __classcell__)r   s   @rG   r   r   k  sQ        ' ' ' ' ' '       rJ   r   r>   c                D    |                      t                                S )z=Check if a type contains any placeholder types (recursively).)r   r   )r   s    rG   has_placeholderr   s  s    ::o''(((rJ   r   Node | NoneDataclassTransformSpec | Nonec                ^   t          | t                    r| j        } t          | t                    r| j        } t          | t
                    r| j        } t          | t                    r3| j        D ]}t          |          }||c S t          | j
                  S t          | t                    r| j        S t          | t                    r| j        } t          | t                    rC| j        dd         D ]}|j        	|j        c S | j        }||j        j        |j        j        S dS )a^  
    Find the dataclass transform spec for the given node, if any exists.

    Per PEP 681 (https://peps.python.org/pep-0681/#the-dataclass-transform-decorator), dataclass
    transforms can be specified in multiple ways, including decorator functions and
    metaclasses/base classes. This function resolves the spec from any of these variants.
    Nr6   )r   r   calleer   r   r   funcr   r   find_dataclass_transform_specimplr   dataclass_transform_specr   r   r   mrometaclass_typerv   )r   	candidatespecbaser  s        rG   r  r  x  sU    $!! 
 {$   y$	""  y$)** 	8
  	 	I0;;D  ,TY777 $   -,,$!! y$!! @HQRRL 	5 	5D,84444 9 ,%.*=*V*b!&??4rJ   api;SemanticAnalyzerInterface | SemanticAnalyzerPluginInterface
expressionr   r   Literal[True, False]c                    d S rB   r   r
  r  r:   r   s       rG   require_bool_literal_argumentr    s	     3rJ   r   c                    d S rB   r   r  s       rG   r  r    s	     #rJ   c                n    t          |          }|#|                     d| d|t                     |S |S )zWAttempt to interpret an expression as a boolean literal, and fail analysis if we can't.N"z*" argument must be a True or False literalrZ   )r   rY   r   )r
  r  r:   r   values        rG   r  r    sP     z""E}@@@@*S^ 	 	
 	
 	
 LrJ   r   c                d    t          | t                    r| j        dk    rdS | j        dk    rdS d S )Nzbuiltins.TrueTzbuiltins.FalseF)r   r   rK   )r   s    rG   r   r     s>    $!! =O++4=,,,54rJ   )r   r+   r   r   r?   r)   )r   r*   r?   rW   )r:   r;   rK   r;   r   r-   r   r   r   r   r   r   r   r   r?   r'   )r   r+   r?   r>   )r   r   r?   r   )
r
  r  r  r   r:   r;   r   r  r?   r>   rB   )
r
  r  r  r   r:   r;   r   rW   r?   r   )
r
  r  r  r   r:   r;   r   r   r?   r   r   )Jr~   
__future__r   abcr   typingr   r   r   r   r	   mypy_extensionsr
   mypy.errorcodesr   r   
mypy.nodesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   mypy.pluginr   mypy.tvar_scoper   mypy.type_visitorr   r   mypy.typeopsr    
mypy.typesr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r5   r   r7   r9   r   r   r   r   r   r   r   r   r  r  r   r   rJ   rG   <module>r!     sn   F F F " " " " " "       ? ? ? ? ? ? ? ? ? ? ? ? ? ? ! ! ! ! ! ! 2 2 2 2 2 2 2 2                                 " 8 7 7 7 7 7 , , , , , , 9 9 9 9 9 9 9 9 . . . . . .                                     , &V  U U U U       L" L" L" L" L" L" L" L"^ p" p" p" p" p" = p" p" p"f     4  4  4  4FW W W W W W W W  $     :  $     2    m   ) ) ) )
F F F FT 
   
 

 	    
  	    "     rJ   