MCPcopy Index your code
hub / github.com/python/mypy / Plugin

Class Plugin

mypy/plugin.py:521–809  ·  view source on GitHub ↗

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_

Source from the content-addressed store, hash-verified

519
520@mypyc_attr(allow_interpreted_subclasses=True)
521class Plugin(CommonPluginApi):
522 """Base class of all type checker plugins.
523
524 This defines a no-op plugin. Subclasses can override some methods to
525 provide some actual functionality.
526
527 All get_ methods are treated as pure functions (you should assume that
528 results might be cached). A plugin should return None from a get_ method
529 to give way to other plugins.
530
531 Look at the comments of various *Context objects for additional information on
532 various hooks.
533 """
534
535 def __init__(self, options: Options) -> None:
536 self.options = options
537 self.python_version = options.python_version
538 # This can't be set in __init__ because it is executed too soon in build.py.
539 # Therefore, build.py *must* set it later before graph processing starts
540 # by calling set_modules().
541 self._modules: dict[str, MypyFile] | None = None
542
543 def set_modules(self, modules: dict[str, MypyFile]) -> None:
544 self._modules = modules
545
546 def lookup_fully_qualified(self, fullname: str) -> SymbolTableNode | None:
547 assert self._modules is not None
548 return lookup_fully_qualified(fullname, self._modules)
549
550 def report_config_data(self, ctx: ReportConfigContext) -> Any:
551 """Get representation of configuration data for a module.
552
553 The data must be encodable as JSON and will be stored in the
554 cache metadata for the module. A mismatch between the cached
555 values and the returned will result in that module's cache
556 being invalidated and the module being rechecked.
557
558 This can be called twice for each module, once after loading
559 the cache to check if it is valid and once while writing new
560 cache information.
561
562 If is_check in the context is true, then the return of this
563 call will be checked against the cached version. Otherwise the
564 call is being made to determine what to put in the cache. This
565 can be used to allow consulting extra cache files in certain
566 complex situations.
567
568 This can be used to incorporate external configuration information
569 that might require changes to typechecking.
570 """
571 return None
572
573 def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]:
574 """Customize dependencies for a module.
575
576 This hook allows adding in new dependencies for a module. It
577 is called after parsing a file but before analysis. This can
578 be useful if a library has dependencies that are dynamic based

Callers 1

_make_managerMethod · 0.90

Calls

no outgoing calls

Tested by 1

_make_managerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…