blob: 5392e64c4f11748c0dbea3d355371270b80e2cbb [file] [log] [blame]
from typing import Optional, Callable
from mypy.plugin import Plugin, MethodContext, FunctionContext
from mypy.types import Type
class ArgKindsPlugin(Plugin):
def get_function_hook(self, fullname: str
) -> Optional[Callable[[FunctionContext], Type]]:
if 'func' in fullname:
return extract_arg_kinds_from_function
return None
def get_method_hook(self, fullname: str
) -> Optional[Callable[[MethodContext], Type]]:
if 'Class.method' in fullname:
return extract_arg_kinds_from_method
return None
def extract_arg_kinds_from_function(ctx: FunctionContext) -> Type:
ctx.api.fail(str([[x.value for x in y] for y in ctx.arg_kinds]), ctx.context)
return ctx.default_return_type
def extract_arg_kinds_from_method(ctx: MethodContext) -> Type:
ctx.api.fail(str([[x.value for x in y] for y in ctx.arg_kinds]), ctx.context)
return ctx.default_return_type
def plugin(version):
return ArgKindsPlugin