| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from typing import Callable |
| 4 |
|
| 5 |
from mypy.plugin import AnalyzeTypeContext, Plugin |
| 6 |
from mypy.types import Type |
| 7 |
|
| 8 |
|
| 9 |
class MyPlugin(Plugin): |
| 10 |
def get_type_analyze_hook(self, fullname: str) -> Callable[[AnalyzeTypeContext], Type] | None: |
| 11 |
if fullname in ("decimal.Decimal", "_decimal.Decimal"): |
| 12 |
return decimal_to_int_hook |
| 13 |
return None |
| 14 |
|
| 15 |
|
| 16 |
def decimal_to_int_hook(ctx: AnalyzeTypeContext) -> Type: |
| 17 |
return ctx.api.named_type("builtins.int", []) |
| 18 |
|
| 19 |
|
| 20 |
def plugin(version: str) -> type[MyPlugin]: |
| 21 |
return MyPlugin |