| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Callable |
| 4 |
|
| 5 |
from mypy.plugin import ClassDefContext, Plugin |
| 6 |
from mypy.plugins.common import add_method |
| 7 |
from mypy.types import NoneType |
| 8 |
|
| 9 |
|
| 10 |
class AddOverrideMethodPlugin(Plugin): |
| 11 |
def get_class_decorator_hook_2(self, fullname: str) -> Callable[[ClassDefContext], bool] | None: |
| 12 |
if fullname == "__main__.inject_foo": |
| 13 |
return add_extra_methods_hook |
| 14 |
return None |
| 15 |
|
| 16 |
|
| 17 |
def add_extra_methods_hook(ctx: ClassDefContext) -> bool: |
| 18 |
add_method(ctx, "foo_implicit", [], NoneType()) |
| 19 |
return True |
| 20 |
|
| 21 |
|
| 22 |
def plugin(version: str) -> type[AddOverrideMethodPlugin]: |
| 23 |
return AddOverrideMethodPlugin |