
    X-Ph-                       d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZmZ 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 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) e G d d                      Z* G d de          Z+ ed           G d d                      Z,e G d d                      Z-e G d d                      Z. G d de          Z/ G d de          Z0 G d de          Z1 G d  d!e          Z2 G d" d#e          Z3 G d$ d%e          Z4 G d& d'e          Z5 G d( d)e          Z6 ed           G d* d+e,                      Z7 e	d,          Z8 G d- d.e7          Z9d/S )0a/  Plugin system for extending mypy.

At large scale the plugin system works as following:

* Plugins are collected from the corresponding mypy config file option
  (either via paths to Python files, or installed Python modules)
  and imported using importlib.

* Every module should get an entry point function (called 'plugin' by default,
  but may be overridden in the config file) that should accept a single string
  argument that is a full mypy version (includes git commit hash for dev
  versions) and return a subclass of mypy.plugins.Plugin.

* All plugin class constructors should match the signature of mypy.plugin.Plugin
  (i.e. should accept an mypy.options.Options object), and *must* call
  super().__init__().

* At several steps during semantic analysis and type checking mypy calls
  special `get_xxx` methods on user plugins with a single string argument that
  is a fully qualified name (full name) of a relevant definition
  (see mypy.plugin.Plugin method docstrings for details).

* The plugins are called in the order they are passed in the config option.
  Every plugin must decide whether to act on a given full name. The first
  plugin that returns non-None object will be used.

* The above decision should be made using the limited common API specified by
  mypy.plugin.CommonPluginApi.

* The callback returned by the plugin will be called with a larger context that
  includes relevant current state (e.g. a default return type, or a default
  attribute type) and a wider relevant API provider (e.g.
  SemanticAnalyzerPluginInterface or CheckerPluginInterface).

* The result of this is used for further processing. See various `XxxContext`
  named tuples for details about which information is given to each hook.

Plugin developers should ensure that their plugins work well in incremental and
daemon modes. In particular, plugins should not hold global state, and should
always call add_plugin_dependency() in plugin hooks called during semantic
analysis. See the method docstring for more details.

There is no dedicated cache storage for plugins, but plugins can store
per-TypeInfo data in a special .metadata attribute that is serialized to the
mypy caches between incremental runs. To avoid collisions between plugins, they
are encouraged to store their state under a dedicated key coinciding with
plugin name in the metadata dictionary. Every value stored there must be
JSON-serializable.

## Notes about the semantic analyzer

Mypy 0.710 introduced a new semantic analyzer that changed how plugins are
expected to work in several notable ways (from mypy 0.730 the old semantic
analyzer is no longer available):

1. The order of processing AST nodes in modules is different. The old semantic
   analyzer processed modules in textual order, one module at a time. The new
   semantic analyzer first processes the module top levels, including bodies of
   any top-level classes and classes nested within classes. ("Top-level" here
   means "not nested within a function/method".) Functions and methods are
   processed only after module top levels have been finished. If there is an
   import cycle, all module top levels in the cycle are processed before
   processing any functions or methods. Each unit of processing (a module top
   level or a function/method) is called a *target*.

   This also means that function signatures in the same module have not been
   analyzed yet when analyzing the module top level. If you need access to
   a function signature, you'll need to explicitly analyze the signature first
   using `anal_type()`.

2. Each target can be processed multiple times. This may happen if some forward
   references are not ready yet, for example. This means that semantic analyzer
   related plugin hooks can be called multiple times for the same full name.
   These plugin methods must thus be idempotent.

3. The `anal_type` API function returns None if some part of the type is not
   available yet. If this happens, the current target being analyzed will be
   *deferred*, which means that it will be processed again soon, in the hope
   that additional dependencies will be available. This may happen if there are
   forward references to types or inter-module references to types within an
   import cycle.

   Note that if there is a circular definition, mypy may decide to stop
   processing to avoid an infinite number of iterations. When this happens,
   `anal_type` will generate an error and return an `AnyType` type object
   during the final iteration (instead of None).

4. There is a new API method `defer()`. This can be used to explicitly request
   the current target to be reprocessed one more time. You don't need this
   to call this if `anal_type` returns None, however.

5. There is a new API property `final_iteration`, which is true once mypy
   detected no progress during the previous iteration or if the maximum
   semantic analysis iteration count has been reached. You must never
   defer during the final iteration, as it will cause a crash.

6. The `node` attribute of SymbolTableNode objects may contain a reference to
   a PlaceholderNode object. This object means that this definition has not
   been fully processed yet. If you encounter a PlaceholderNode, you should
   defer unless it's the final iteration. If it's the final iteration, you
   should generate an error message. It usually means that there's a cyclic
   definition that cannot be resolved by mypy. PlaceholderNodes can only refer
   to references inside an import cycle. If you are looking up things from
   another module, such as the builtins, that is outside the current module or
   import cycle, you can safely assume that you won't receive a placeholder.

When testing your plugin, you should have a test case that forces a module top
level to be processed multiple times. The easiest way to do this is to include
a forward reference to a class in a top-level annotation. Example:

    c: C  # Forward reference causes second analysis pass
    class C: pass

Note that a forward reference in a function signature won't trigger another
pass, since all functions are processed only after the top level has been fully
analyzed.
    )annotations)abstractmethod)AnyCallable
NamedTupleTypeVar)
mypyc_attrtrait)	ErrorCode)lookup_fully_qualified)ErrorMessage)MessageBuilder)ArgKindCallExprClassDefContext
ExpressionMypyFileSymbolTableNodeTypeInfo)Options)TypeVarLikeScope)CallableTypeFunctionLikeInstance
ProperTypeTypeTypeListUnboundTypec                      e Zd ZU dZded<   edddd            Zedd            Zedd            Zedd            Z	dS )TypeAnalyzerPluginInterfacezInterface for accessing semantic analyzer functionality in plugins.

    Methods docstrings contain only basic info. Look for corresponding implementation
    docstrings in typeanal.py for more details.
    r   optionsNcodemsgstrctxr   r$   ErrorCode | NonereturnNonec                   t           z(Emit an error message at given location.NotImplementedErrorselfr%   r'   r$   s       K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/plugin.pyfailz TypeAnalyzerPluginInterface.fail   
     "!    fullnameargs
list[Type]r   c                   t           )z8Construct an instance of a builtin type with given name.r-   r0   r5   r6   s      r1   
named_typez&TypeAnalyzerPluginInterface.named_type   r3   r4   typr   c                   t           )z5Analyze an unbound type using the default mypy logic.r-   )r0   r;   s     r1   analyze_typez(TypeAnalyzerPluginInterface.analyze_type   r3   r4   arglistr   9tuple[list[Type], list[ArgKind], list[str | None]] | Nonec                    t           )zHFind types, kinds, and names of arguments from extended callable syntax.r-   )r0   r>   s     r1   analyze_callable_argsz1TypeAnalyzerPluginInterface.analyze_callable_args   
    
 "!r4   )r%   r&   r'   r   r$   r(   r)   r*   )r5   r&   r6   r7   r)   r   )r;   r   r)   r   )r>   r   r)   r?   )
__name__
__module____qualname____doc____annotations__r   r2   r:   r=   rA    r4   r1   r!   r!      s           GK " " " " " ^" " " " ^" " " " ^" " " " ^" " "r4   r!   c                  .    e Zd ZU ded<   ded<   ded<   dS )AnalyzeTypeContextr   typer   contextr!   apiNrC   rD   rE   rG   rH   r4   r1   rJ   rJ      s6         $$$$$$r4   rJ   T)allow_interpreted_subclassesc                  6    e Zd ZU dZded<   ed
d            Zd	S )CommonPluginApiz
    A common plugin API (shared between semantic analysis and type checking phases)
    that all plugin hooks get independently of the context.
    r   r"   r5   r&   r)   SymbolTableNode | Nonec                    t           )a  Lookup a symbol by its full name (including module).

        This lookup function available for all plugins. Return None if a name
        is not found. This function doesn't support lookup from current scope.
        Use SemanticAnalyzerPluginInterface.lookup_qualified() for this.r-   r0   r5   s     r1   r   z&CommonPluginApi.lookup_fully_qualified   s
     "!r4   Nr5   r&   r)   rR   )rC   rD   rE   rF   rG   r   r   rH   r4   r1   rQ   rQ      sL           " " " ^" " "r4   rQ   c                      e Zd ZU dZded<   ded<   ded<   eedd
                        Zeddd d            Zed!d            Z	ed"d#d            Z
dS )$CheckerPluginInterfacezInterface for accessing type checker functionality in plugins.

    Methods docstrings contain only basic info. Look for corresponding implementation
    docstrings in checker.py for more details.
    r   r%   r   r"   r&   pathr)   list[Type | None]c                    t           )z%Return the type context of the pluginr-   r0   s    r1   type_contextz#CheckerPluginInterface.type_context   
     "!r4   Nr#   str | ErrorMessager'   r   r$   r(   r*   c                  t           r,   r-   r/   s       r1   r2   zCheckerPluginInterface.fail   rB   r4   namer6   r7   r   c                    t           )zBConstruct an instance of a generic type with given type arguments.r-   )r0   r`   r6   s      r1   named_generic_typez)CheckerPluginInterface.named_generic_type   r3   r4   noder   r\   Type | Noner   c                    t           )z(Checks the type of the given expression.r-   )r0   rc   r\   s      r1   get_expression_typez*CheckerPluginInterface.get_expression_type   r3   r4   )r)   rY   )r%   r^   r'   r   r$   r(   r)   r*   )r`   r&   r6   r7   r)   r   N)rc   r   r\   rd   r)   r   )rC   rD   rE   rF   rG   propertyr   r\   r2   rb   rf   rH   r4   r1   rW   rW      s           III " " " ^ X" TX" " " " " ^" " " " ^" " " " " ^" " "r4   rW   c                  F   e Zd ZU dZded<   ded<   ded<   ded	<   edLdMd            ZedNd            ZedLdOd            ZedPd            Z	edQd            Z
edRd             Ze	 dSd!d
d"dTd+            Zed
d!d!d,d-dUd6            ZedVd8            ZedWd:            ZedXd<            Ze	 dSdYd>            ZedLdZdA            Zed[dD            Zed\dE            Zed]dF            Zeed^dG                        Zeed^dH                        Zed_dK            Zd
S )`SemanticAnalyzerPluginInterfacezInterface for accessing semantic analyzer functionality in plugins.

    Methods docstrings contain only basic info. Look for corresponding implementation
    docstrings in semanal.py for more details.

    # TODO: clean-up lookup functions.
    dict[str, MypyFile]modulesr   r"   r&   
cur_mod_idr   r%   Nr5   r6   list[Type] | Noner)   r   c                    t           )zBConstruct an instance of a builtin type with given type arguments.r-   r9   s      r1   r:   z*SemanticAnalyzerPluginInterface.named_type  r3   r4   fully_qualified_namec                    t           )z,Legacy function -- use named_type() instead.r-   )r0   rp   s     r1   builtin_typez,SemanticAnalyzerPluginInterface.builtin_type  r]   r4   Instance | Nonec                    t           )a  Construct an instance of a type with given type arguments.

        Return None if a type could not be constructed for the qualified
        type name. This is possible when the qualified name includes a
        module name and the module has not been imported.
        r-   r9   s      r1   named_type_or_nonez2SemanticAnalyzerPluginInterface.named_type_or_none  
     "!r4   r`   basetype_or_fallbacklineintr   c                    t           rg   r-   )r0   r`   rw   rx   s       r1   basic_new_typeinfoz2SemanticAnalyzerPluginInterface.basic_new_typeinfo%      !!r4   exprr   bool | Nonec                    t           )zParse True/False literals.r-   r0   r}   s     r1   
parse_boolz*SemanticAnalyzerPluginInterface.parse_bool)  r3   r4   
str | Nonec                    dS )zParse string literals.NrH   r   s     r1   parse_str_literalz1SemanticAnalyzerPluginInterface.parse_str_literal.  s      r4   F)blockerr$   r'   r   seriousboolr   r$   r(   r*   c                   t           r,   r-   )r0   r%   r'   r   r   r$   s         r1   r2   z$SemanticAnalyzerPluginInterface.fail2  s
     "!r4   T)
tvar_scopeallow_tuple_literalallow_unbound_tvarsreport_invalid_typesr;   r   r   TypeVarLikeScope | Noner   r   r   rd   c                  t           )zAnalyze an unbound type.

        Return None if some part of the type is not ready yet. In this
        case the current target being analyzed will be deferred and
        analyzed again.
        r-   )r0   r;   r   r   r   r   s         r1   	anal_typez)SemanticAnalyzerPluginInterface.anal_type?  s
    " "!r4   	self_typec                    t           )zCGenerate type of first argument of class methods from type of self.r-   )r0   r   s     r1   
class_typez*SemanticAnalyzerPluginInterface.class_typeR  r3   r4   r   c                   t           )z[Lookup a symbol by its fully qualified name.

        Raise an error if not found.
        r-   rT   s     r1   r   z6SemanticAnalyzerPluginInterface.lookup_fully_qualifiedW  
     "!r4   rR   c                   t           )zXLookup a symbol by its fully qualified name.

        Return None if not found.
        r-   rT   s     r1   lookup_fully_qualified_or_nonez>SemanticAnalyzerPluginInterface.lookup_fully_qualified_or_none_  r   r4   suppress_errorsc                    t           )z|Lookup symbol using a name in current scope.

        This follows Python local->non-local->global->builtins rules.
        r-   )r0   r`   r'   r   s       r1   lookup_qualifiedz0SemanticAnalyzerPluginInterface.lookup_qualifiedg  rv   r4   triggertargetc                    t           )a  Specify semantic dependencies for generated methods/variables.

        If the symbol with full name given by trigger is found to be stale by mypy,
        then the body of node with full name given by target will be re-checked.
        By default, this is the node that is currently analyzed.

        For example, the dataclass plugin adds a generated __init__ method with
        a signature that depends on types of attributes in ancestor classes. If any
        attribute in an ancestor class gets stale (modified), we need to reprocess
        the subclasses (and thus regenerate __init__ methods).

        This is used by fine-grained incremental mode (mypy daemon). See mypy/server/deps.py
        for more details.
        r-   )r0   r   r   s      r1   add_plugin_dependencyz5SemanticAnalyzerPluginInterface.add_plugin_dependencyq  s
      "!r4   symbolr   c                    t           )zFAdd node to global symbol table (or to nearest class if there is one).r-   )r0   r`   r   s      r1   add_symbol_table_nodez5SemanticAnalyzerPluginInterface.add_symbol_table_node  r3   r4   c                    t           )zFMake qualified name using current module and enclosing class (if any).r-   )r0   r`   s     r1   qualified_namez.SemanticAnalyzerPluginInterface.qualified_name  r3   r4   c                    t           )zCall this to defer the processing of the current node.

        This will request an additional iteration of semantic analysis.
        r-   r[   s    r1   deferz%SemanticAnalyzerPluginInterface.defer  r   r4   c                    t           )z1Is this the final iteration of semantic analysis?r-   r[   s    r1   final_iterationz/SemanticAnalyzerPluginInterface.final_iteration  r]   r4   c                    t           rg   r-   r[   s    r1   is_stub_filez,SemanticAnalyzerPluginInterface.is_stub_file  r3   r4   rvalueis_finalc                    t           rg   r-   )r0   r   r   s      r1   analyze_simple_literal_typez;SemanticAnalyzerPluginInterface.analyze_simple_literal_type  r|   r4   rg   )r5   r&   r6   rn   r)   r   )rp   r&   r)   r   )r5   r&   r6   rn   r)   rs   )r`   r&   rw   r   rx   ry   r)   r   )r}   r   r)   r~   )r}   r   r)   r   )F)r%   r&   r'   r   r   r   r   r   r$   r(   r)   r*   )r;   r   r   r   r   r   r   r   r   r   r)   rd   )r   r   r)   r   )r5   r&   r)   r   rU   )r`   r&   r'   r   r   r   r)   rR   )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)   rd   )rC   rD   rE   rF   rG   r   r:   rr   ru   r{   r   r   r2   r   r   r   r   r   r   r   r   r   rh   r   r   r   rH   r4   r1   rj   rj      s          !   OOO" " " " ^" " " " ^"
 " " " " ^" " " " ^" " " " ^" % % % ^% 
 	
" !%
" 
" 
" 
" 
" ^
"  /3$)$)%)" " " " " ^"$ " " " ^" " " " ^" " " " ^" ?D" " " " ^" " " " " ^"" " " " ^" " " " ^" " " " ^" " " " ^ X" " " " ^ X" " " " ^" " "r4   rj   c                  .    e Zd ZU ded<   ded<   ded<   dS )ReportConfigContextr&   idrX   r   is_checkNrN   rH   r4   r1   r   r     s+         GGGIIINNNNNr4   r   c                  8    e Zd ZU ded<   ded<   ded<   ded<   d	S )
FunctionSigContextlist[list[Expression]]r6   r   default_signaturer   rL   rW   rM   NrN   rH   r4   r1   r   r     sB             ####r4   r   c                  `    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   dS )FunctionContextlist[list[Type]]	arg_typeslist[list[ArgKind]]	arg_kindslist[str | None]callee_arg_nameslist[list[str | None]]	arg_namesr   default_return_typer   r6   r   rL   rW   rM   NrN   rH   r4   r1   r   r     sv         """" '&&& &%%%    r4   r   c                  B    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   dS )MethodSigContextr   rK   r   r6   r   r   r   rL   rW   rM   NrN   rH   r4   r1   r   r     sN             ####r4   r   c                  j    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<   dS )MethodContextr   rK   r   r   r   r   r   r   r   r   r   r   r   r6   r   rL   rW   rM   NrN   rH   r4   r1   r   r     s~         """"&&&&%%%%    r4   r   c                  B    e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   dS )AttributeContextr   rK   r   default_attr_typer   	is_lvaluer   rL   rW   rM   NrN   rH   r4   r1   r   r     sK         OOOr4   r   c                  .    e Zd ZU ded<   ded<   ded<   dS )ClassDefContextr   clsr   reasonrj   rM   NrN   rH   r4   r1   r   r     s3         MMM((((((r4   r   c                  .    e Zd ZU ded<   ded<   ded<   dS )DynamicClassDefContextr   callr&   r`   rj   rM   NrN   rH   r4   r1   r   r     s0         NNNIII((((((r4   r   c                      e Zd ZdZd-dZd.d	Zd/dZd0dZd1dZd2dZ	d3dZ
d4dZd5dZd6dZd7d!Zd7d"Zd8d$Zd9d&Zd8d'Zd8d(Zd8d)Zd:d+Zd,S );Plugina  Base class of all type checker plugins.

    This defines a no-op plugin.  Subclasses can override some methods to
    provide some actual functionality.

    All get_ methods are treated as pure functions (you should assume that
    results might be cached). A plugin should return None from a get_ method
    to give way to other plugins.

    Look at the comments of various *Context objects for additional information on
    various hooks.
    r"   r   r)   r*   c                :    || _         |j        | _        d | _        d S rg   )r"   python_version_modules)r0   r"   s     r1   __init__zPlugin.__init__  s!    %4 59r4   rl   rk   c                    || _         d S rg   )r   )r0   rl   s     r1   set_moduleszPlugin.set_modules  s    r4   r5   r&   rR   c                >    | j         J t          || j                   S rg   )r   r   rT   s     r1   r   zPlugin.lookup_fully_qualified  s"    }(((%h>>>r4   r'   r   r   c                    dS )a  Get representation of configuration data for a module.

        The data must be encodable as JSON and will be stored in the
        cache metadata for the module. A mismatch between the cached
        values and the returned will result in that module's cache
        being invalidated and the module being rechecked.

        This can be called twice for each module, once after loading
        the cache to check if it is valid and once while writing new
        cache information.

        If is_check in the context is true, then the return of this
        call will be checked against the cached version. Otherwise the
        call is being made to determine what to put in the cache. This
        can be used to allow consulting extra cache files in certain
        complex situations.

        This can be used to incorporate external configuration information
        that might require changes to typechecking.
        NrH   )r0   r'   s     r1   report_config_datazPlugin.report_config_data"  s	    * tr4   filer   list[tuple[int, str, int]]c                    g S )a;  Customize dependencies for a module.

        This hook allows adding in new dependencies for a module. It
        is called after parsing a file but before analysis. This can
        be useful if a library has dependencies that are dynamic based
        on configuration information, for example.

        Returns a list of (priority, module name, line number) tuples.

        The line number can be -1 when there is not a known real line number.

        Priorities are defined in mypy.build (but maybe shouldn't be).
        10 is a good choice for priority.
        rH   )r0   r   s     r1   get_additional_depszPlugin.get_additional_deps9  s	     	r4   +Callable[[AnalyzeTypeContext], Type] | Nonec                    dS )a+  Customize behaviour of the type analyzer for given full names.

        This method is called during the semantic analysis pass whenever mypy sees an
        unbound type. For example, while analysing this code:

            from lib import Special, Other

            var: Special
            def func(x: Other[int]) -> None:
                ...

        this method will be called with 'lib.Special', and then with 'lib.Other'.
        The callback returned by plugin must return an analyzed type,
        i.e. an instance of `mypy.types.Type`.
        NrH   rT   s     r1   get_type_analyze_hookzPlugin.get_type_analyze_hookJ  	      tr4   3Callable[[FunctionSigContext], FunctionLike] | Nonec                    dS )aX  Adjust the signature of a function.

        This method is called before type checking a function call. Plugin
        may infer a better type for the function.

            from lib import Class, do_stuff

            do_stuff(42)
            Class()

        This method will be called with 'lib.do_stuff' and then with 'lib.Class'.
        NrH   rT   s     r1   get_function_signature_hookz"Plugin.get_function_signature_hook\  	     tr4   (Callable[[FunctionContext], Type] | Nonec                    dS )a  Adjust the return type of a function call.

        This method is called after type checking a call. Plugin may adjust the return
        type inferred by mypy, and/or emit some error messages. Note, this hook is also
        called for class instantiation calls, so that in this example:

            from lib import Class, do_stuff

            do_stuff(42)
            Class()

        This method will be called with 'lib.do_stuff' and then with 'lib.Class'.
        NrH   rT   s     r1   get_function_hookzPlugin.get_function_hookm  s	     tr4   1Callable[[MethodSigContext], FunctionLike] | Nonec                    dS )aN  Adjust the signature of a method.

        This method is called before type checking a method call. Plugin
        may infer a better type for the method. The hook is also called for special
        Python dunder methods except __init__ and __new__ (use get_function_hook to customize
        class instantiation). This function is called with the method full name using
        the class where it was _defined_. For example, in this code:

            from lib import Special

            class Base:
                def method(self, arg: Any) -> Any:
                    ...
            class Derived(Base):
                ...

            var: Derived
            var.method(42)

            x: Special
            y = x[0]

        this method is called with '__main__.Base.method', and then with
        'lib.Special.__getitem__'.
        NrH   rT   s     r1   get_method_signature_hookz Plugin.get_method_signature_hook}  s	    8 tr4   &Callable[[MethodContext], Type] | Nonec                    dS )zAdjust return type of a method call.

        This is the same as get_function_hook(), but is called with the
        method full name (again, using the class where the method is defined).
        NrH   rT   s     r1   get_method_hookzPlugin.get_method_hook  s	     tr4   )Callable[[AttributeContext], Type] | Nonec                    dS )a8  Adjust type of an instance attribute.

        This method is called with attribute full name using the class of the instance where
        the attribute was defined (or Var.info.fullname for generated attributes).

        For classes without __getattr__ or __getattribute__, this hook is only called for
        names of fields/properties (but not methods) that exist in the instance MRO.

        For classes that implement __getattr__ or __getattribute__, this hook is called
        for all fields/properties, including nonexistent ones (but still not methods).

        For example:

            class Base:
                x: Any
                def __getattr__(self, attr: str) -> Any: ...

            class Derived(Base):
                ...

            var: Derived
            var.x
            var.y

        get_attribute_hook is called with '__main__.Base.x' and '__main__.Base.y'.
        However, if we had not implemented __getattr__ on Base, you would only get
        the callback for 'var.x'; 'var.y' would produce an error without calling the hook.
        NrH   rT   s     r1   get_attribute_hookzPlugin.get_attribute_hook  s	    : tr4   c                    dS )a{  
        Adjust type of a class attribute.

        This method is called with attribute full name using the class where the attribute was
        defined (or Var.info.fullname for generated attributes).

        For example:

            class Cls:
                x: Any

            Cls.x

        get_class_attribute_hook is called with '__main__.Cls.x' as fullname.
        NrH   rT   s     r1   get_class_attribute_hookzPlugin.get_class_attribute_hook  r   r4   (Callable[[ClassDefContext], None] | Nonec                    dS )a  Update class definition for given class decorators.

        The plugin can modify a TypeInfo _in place_ (for example add some generated
        methods to the symbol table). This hook is called after the class body was
        semantically analyzed, but *there may still be placeholders* (typically
        caused by forward references).

        NOTE: Usually get_class_decorator_hook_2 is the better option, since it
              guarantees that there are no placeholders.

        The hook is called with full names of all class decorators.

        The hook can be called multiple times per class, so it must be
        idempotent.
        NrH   rT   s     r1   get_class_decorator_hookzPlugin.get_class_decorator_hook  r   r4   (Callable[[ClassDefContext], bool] | Nonec                    dS )a  Update class definition for given class decorators.

        Similar to get_class_decorator_hook, but this runs in a later pass when
        placeholders have been resolved.

        The hook can return False if some base class hasn't been
        processed yet using class hooks. It causes all class hooks
        (that are run in this same pass) to be invoked another time for
        the file(s) currently being processed.

        The hook can be called multiple times per class, so it must be
        idempotent.
        NrH   rT   s     r1   get_class_decorator_hook_2z!Plugin.get_class_decorator_hook_2  r   r4   c                    dS )a2  Update class definition for given declared metaclasses.

        Same as get_class_decorator_hook() but for metaclasses. Note:
        this hook will be only called for explicit metaclasses, not for
        inherited ones.

        TODO: probably it should also be called on inherited metaclasses.
        NrH   rT   s     r1   get_metaclass_hookzPlugin.get_metaclass_hook  s	     tr4   c                    dS )a  Update class definition for given base classes.

        Same as get_class_decorator_hook() but for base classes. Base classes
        don't need to refer to TypeInfos, if a base class refers to a variable with
        Any type, this hook will still be called.
        NrH   rT   s     r1   get_base_class_hookzPlugin.get_base_class_hook  s	     tr4   c                    dS )zCustomize MRO for given classes.

        The plugin can modify the class MRO _in place_. This method is called
        with the class full name before its body was semantically analyzed.
        NrH   rT   s     r1   get_customize_class_mro_hookz#Plugin.get_customize_class_mro_hook  s	     tr4   /Callable[[DynamicClassDefContext], None] | Nonec                    dS )a  Semantically analyze a dynamic class definition.

        This plugin hook allows one to semantically analyze dynamic class definitions like:

            from lib import dynamic_class

            X = dynamic_class('X', [])

        For such definition, this hook will be called with 'lib.dynamic_class'.
        The plugin should create the corresponding TypeInfo, and place it into a relevant
        symbol table, e.g. using ctx.api.add_symbol_table_node().
        NrH   rT   s     r1   get_dynamic_class_hookzPlugin.get_dynamic_class_hook  r   r4   N)r"   r   r)   r*   rl   rk   r)   r*   rU   r'   r   r)   r   r   r   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   r5   r&   r)   r   )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rH   r4   r1   r   r     s        9 9 9 9       ? ? ? ?   .   "   $   "       <      >   $   $   $	 	 	 	           r4   r   Tc                       e Zd ZdZd0 fdZd1dZd2dZd3dZd4dZd5dZ	d6dZ
d7dZd8dZd9d!Zd9d"Zd:d$Zd;d&Zd:d'Zd:d(Zd:d)Zd<d+Zd=d/Z xZS )>ChainedPluginzA plugin that represents a sequence of chained plugins.

    Each lookup method returns the hook for the first plugin that
    reports a match.

    This class should not be subclassed -- use Plugin as the base class
    for all plugins.
    r"   r   pluginslist[Plugin]r)   r*   c                X    t                                          |           || _        dS )zrInitialize chained plugin.

        Assume that the child plugins aren't mutated (results may be cached).
        N)superr   _plugins)r0   r"   r  	__class__s      r1   r   zChainedPlugin.__init__7  s(    
 	!!!r4   rl   rk   c                D    | j         D ]}|                    |           d S rg   )r  r   )r0   rl   plugins      r1   r   zChainedPlugin.set_modules?  s4    m 	( 	(Fw''''	( 	(r4   r'   r   r   c                d    fd| j         D             }t          d |D                       r|nd S )Nc                :    g | ]}|                               S rH   )r   ).0r  r'   s     r1   
<listcomp>z4ChainedPlugin.report_config_data.<locals>.<listcomp>D  s'    RRR&v0055RRRr4   c              3     K   | ]}|d uV  	d S rg   rH   )r  xs     r1   	<genexpr>z3ChainedPlugin.report_config_data.<locals>.<genexpr>E  s&      !E!EA!4-!E!E!E!E!E!Er4   )r  any)r0   r'   config_datas    ` r1   r   z ChainedPlugin.report_config_dataC  sD    RRRRDMRRR!!E!E!E!E!EEEO{{4Or4   r   r   r   c                n    g }| j         D ]*}|                    |                    |                     +|S rg   )r  extendr   )r0   r   depsr  s       r1   r   z!ChainedPlugin.get_additional_depsG  s@    m 	: 	:FKK224889999r4   r5   r&   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r  r5   s    r1   <lambda>z5ChainedPlugin.get_type_analyze_hook.<locals>.<lambda>N  s    f.J.J8.T.T r4   
_find_hookrT   s    `r1   r   z#ChainedPlugin.get_type_analyze_hookM  s    TTTTUUUr4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z;ChainedPlugin.get_function_signature_hook.<locals>.<lambda>S  s    f.P.PQY.Z.Z r4   r*  rT   s    `r1   r   z)ChainedPlugin.get_function_signature_hookP  s!     ZZZZ[[[r4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z1ChainedPlugin.get_function_hook.<locals>.<lambda>V  s    f.F.Fx.P.P r4   r*  rT   s    `r1   r   zChainedPlugin.get_function_hookU  s    PPPPQQQr4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z9ChainedPlugin.get_method_signature_hook.<locals>.<lambda>[  s    f.N.Nx.X.X r4   r*  rT   s    `r1   r   z'ChainedPlugin.get_method_signature_hookX  s!     XXXXYYYr4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z/ChainedPlugin.get_method_hook.<locals>.<lambda>^  s    f.D.DX.N.N r4   r*  rT   s    `r1   r   zChainedPlugin.get_method_hook]  s    NNNNOOOr4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z2ChainedPlugin.get_attribute_hook.<locals>.<lambda>a      f.G.G.Q.Q r4   r*  rT   s    `r1   r   z ChainedPlugin.get_attribute_hook`      QQQQRRRr4   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z8ChainedPlugin.get_class_attribute_hook.<locals>.<lambda>d      f.M.Mh.W.W r4   r*  rT   s    `r1   r   z&ChainedPlugin.get_class_attribute_hookc      WWWWXXXr4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z8ChainedPlugin.get_class_decorator_hook.<locals>.<lambda>g  r:  r4   r*  rT   s    `r1   r   z&ChainedPlugin.get_class_decorator_hookf  r;  r4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z:ChainedPlugin.get_class_decorator_hook_2.<locals>.<lambda>l  s    f.O.OPX.Y.Y r4   r*  rT   s    `r1   r   z(ChainedPlugin.get_class_decorator_hook_2i  s!     YYYYZZZr4   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z2ChainedPlugin.get_metaclass_hook.<locals>.<lambda>o  r6  r4   r*  rT   s    `r1   r   z ChainedPlugin.get_metaclass_hookn  r7  r4   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z3ChainedPlugin.get_base_class_hook.<locals>.<lambda>r  s    f.H.H.R.R r4   r*  rT   s    `r1   r   z!ChainedPlugin.get_base_class_hookq  s    RRRRSSSr4   c                4    |                      fd          S )Nc                .    |                                S rg   )r   r(  s    r1   r)  z<ChainedPlugin.get_customize_class_mro_hook.<locals>.<lambda>w  s    f.Q.QRZ.[.[ r4   r*  rT   s    `r1   r   z*ChainedPlugin.get_customize_class_mro_hookt  s!     [[[[\\\r4   r   c                4    |                      fd          S )Nc                .    |                                S rg   )r  r(  s    r1   r)  z6ChainedPlugin.get_dynamic_class_hook.<locals>.<lambda>|  s    f.K.KH.U.U r4   r*  rT   s    `r1   r  z$ChainedPlugin.get_dynamic_class_hooky  s!     UUUUVVVr4   lookupCallable[[Plugin], T]T | Nonec                <    | j         D ]} ||          }|r|c S d S rg   )r  )r0   rH  r  hooks       r1   r+  zChainedPlugin._find_hook~  s;    m 	 	F6&>>D tr4   )r"   r   r  r  r)   r*   r  r  r  r  r  r  r	  r
  r  r  r  r  )rH  rI  r)   rJ  )rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r+  __classcell__)r  s   @r1   r  r  +  s                   ( ( ( (P P P P   V V V V\ \ \ \
R R R RZ Z Z Z
P P P PS S S SY Y Y YY Y Y Y[ [ [ [
S S S ST T T T] ] ] ]
W W W W
       r4   r  N):rF   
__future__r   abcr   typingr   r   r   r   mypy_extensionsr	   r
   mypy.errorcodesr   mypy.lookupr   mypy.message_registryr   mypy.messagesr   
mypy.nodesr   r   r   r   r   r   r   r   mypy.optionsr   mypy.tvar_scoper   
mypy.typesr   r   r   r   r   r   r   r!   rJ   rQ   rW   rj   r   r   r   r   r   r   r   r   r   r  r  rH   r4   r1   <module>rZ     s  t tl # " " " " "       5 5 5 5 5 5 5 5 5 5 5 5 - - - - - - - - % % % % % % . . . . . . . . . . . . ( ( ( ( ( (	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !           , , , , , ,                  !" !" !" !" !" !" !" !"J% % % % % % % % ..." " " " " " " /."* !" !" !" !" !" !" !" !"H a" a" a" a" a" a" a" a"L    *                           j      .         z      
  
  
  
  
 J 
  
  
          z      ) ) ) ) )j ) ) )) ) ) ) )Z ) ) ) ...` ` ` ` `_ ` ` /.`F	 GCLLX X X X XF X X X X Xr4   