| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Callable |
| 4 |
|
| 5 |
from mypy.plugin import MethodSigContext, Plugin |
| 6 |
from mypy.types import CallableType |
| 7 |
|
| 8 |
|
| 9 |
class FullyQualifiedTestPlugin(Plugin): |
| 10 |
def get_method_signature_hook( |
| 11 |
self, fullname: str |
| 12 |
) -> Callable[[MethodSigContext], CallableType] | None: |
| 13 |
# Ensure that all names are fully qualified |
| 14 |
if "FullyQualifiedTest" in fullname: |
| 15 |
assert fullname.startswith("__main__.") and " of " not in fullname, fullname |
| 16 |
return my_hook |
| 17 |
|
| 18 |
return None |
| 19 |
|
| 20 |
|
| 21 |
def my_hook(ctx: MethodSigContext) -> CallableType: |
| 22 |
return ctx.default_signature.copy_modified( |
| 23 |
ret_type=ctx.api.named_generic_type("builtins.int", []) |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
def plugin(version: str) -> type[FullyQualifiedTestPlugin]: |
| 28 |
return FullyQualifiedTestPlugin |