A 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.
| 813 | |
| 814 | |
| 815 | class ChainedPlugin(Plugin): |
| 816 | """A plugin that represents a sequence of chained plugins. |
| 817 | |
| 818 | Each lookup method returns the hook for the first plugin that |
| 819 | reports a match. |
| 820 | |
| 821 | This class should not be subclassed -- use Plugin as the base class |
| 822 | for all plugins. |
| 823 | """ |
| 824 | |
| 825 | # TODO: Support caching of lookup results (through a LRU cache, for example). |
| 826 | |
| 827 | def __init__(self, options: Options, plugins: list[Plugin]) -> None: |
| 828 | """Initialize chained plugin. |
| 829 | |
| 830 | Assume that the child plugins aren't mutated (results may be cached). |
| 831 | """ |
| 832 | super().__init__(options) |
| 833 | self._plugins = plugins |
| 834 | |
| 835 | def set_modules(self, modules: dict[str, MypyFile]) -> None: |
| 836 | for plugin in self._plugins: |
| 837 | plugin.set_modules(modules) |
| 838 | |
| 839 | def report_config_data(self, ctx: ReportConfigContext) -> Any: |
| 840 | config_data = [plugin.report_config_data(ctx) for plugin in self._plugins] |
| 841 | return config_data if any(x is not None for x in config_data) else None |
| 842 | |
| 843 | def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]: |
| 844 | deps = [] |
| 845 | for plugin in self._plugins: |
| 846 | deps.extend(plugin.get_additional_deps(file)) |
| 847 | return deps |
| 848 | |
| 849 | def get_type_analyze_hook(self, fullname: str) -> Callable[[AnalyzeTypeContext], Type] | None: |
| 850 | # Micro-optimization: Inline iteration over plugins |
| 851 | for plugin in self._plugins: |
| 852 | hook = plugin.get_type_analyze_hook(fullname) |
| 853 | if hook is not None: |
| 854 | return hook |
| 855 | return None |
| 856 | |
| 857 | def get_function_signature_hook( |
| 858 | self, fullname: str |
| 859 | ) -> Callable[[FunctionSigContext], FunctionLike] | None: |
| 860 | # Micro-optimization: Inline iteration over plugins |
| 861 | for plugin in self._plugins: |
| 862 | hook = plugin.get_function_signature_hook(fullname) |
| 863 | if hook is not None: |
| 864 | return hook |
| 865 | return None |
| 866 | |
| 867 | def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type] | None: |
| 868 | return self._find_hook(lambda plugin: plugin.get_function_hook(fullname)) |
| 869 | |
| 870 | def get_method_signature_hook( |
| 871 | self, fullname: str |
| 872 | ) -> Callable[[MethodSigContext], FunctionLike] | None: |
no outgoing calls
no test coverage detected
searching dependent graphs…