| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Callable |
| 4 |
|
| 5 |
from mypy.plugin import FunctionContext, MethodContext, Plugin |
| 6 |
from mypy.types import Type |
| 7 |
|
| 8 |
|
| 9 |
class ArgKindsPlugin(Plugin): |
| 10 |
def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type] | None: |
| 11 |
if "func" in fullname: |
| 12 |
return extract_arg_kinds_from_function |
| 13 |
return None |
| 14 |
|
| 15 |
def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | None: |
| 16 |
if "Class.method" in fullname: |
| 17 |
return extract_arg_kinds_from_method |
| 18 |
return None |
| 19 |
|
| 20 |
|
| 21 |
def extract_arg_kinds_from_function(ctx: FunctionContext) -> Type: |
| 22 |
ctx.api.fail(str([[x.value for x in y] for y in ctx.arg_kinds]), ctx.context) |
| 23 |
return ctx.default_return_type |
| 24 |
|
| 25 |
|
| 26 |
def extract_arg_kinds_from_method(ctx: MethodContext) -> Type: |
| 27 |
ctx.api.fail(str([[x.value for x in y] for y in ctx.arg_kinds]), ctx.context) |
| 28 |
return ctx.default_return_type |
| 29 |
|
| 30 |
|
| 31 |
def plugin(version: str) -> type[ArgKindsPlugin]: |
| 32 |
return ArgKindsPlugin |