autogen/python/mypy_plugin.py
Jack Gerrits dda208f9b4
Add component config support (#4757)
* Add wip component impl

* finishing touches

* remove test file

* fix json usage

* Format

---------

Co-authored-by: Victor Dibia <victordibia@microsoft.com>
2024-12-20 13:14:24 -05:00

23 lines
745 B
Python

from typing import Callable
from mypy.plugin import Plugin, DynamicClassDefContext, SymbolTableNode
from mypy.nodes import SymbolTableNode
class CustomPlugin(Plugin):
def get_dynamic_class_hook(
self, fullname: str
) -> Callable[[DynamicClassDefContext], None] | None:
def hook(ctx: DynamicClassDefContext) -> None:
if "Component" in fullname:
# We need to generate mypy.nodes.TypeInfo
# to make mypy understand the type of the class
ctx.api.add_symbol_table_node(
fullname, SymbolTableNode(
)
)
return
def plugin(version: str):
# ignore version argument if the plugin works with all mypy versions.
return CustomPlugin