|
1 | 1 | from mypy.types import LiteralType, AnyType, TypeOfAny, Type |
2 | 2 | from mypy.plugin import Plugin, MethodContext |
3 | | -from typing import Callable |
| 3 | +from typing import Callable, Optional |
4 | 4 |
|
5 | 5 | # If radd exists, there shouldn't be an error. If it doesn't exist, then there will be an error |
6 | | -def type_add(ctx: MethodContext, *args) -> Type: |
7 | | - ctx.api.fail("test", ctx.context) |
| 6 | +def type_add(ctx: MethodContext) -> Type: |
| 7 | + ctx.api.fail("fail", ctx.context) |
8 | 8 | return AnyType(TypeOfAny.from_error) |
9 | 9 |
|
10 | | -def type_radd(ctx: MethodContext, *args) -> Type: |
11 | | - lhs = ctx.type |
12 | | - rhs = ctx.arg_types[-1][0] |
13 | | - if not (isinstance(lhs, LiteralType) and isinstance(rhs, LiteralType)): |
14 | | - ctx.api.fail("operands not literals", ctx.context) |
15 | | - return AnyType(TypeOfAny.from_error) |
16 | | - if not (isinstance(lhs.value, int) and isinstance(rhs.value, int)): |
17 | | - ctx.api.fail("operands not literal ints", ctx.context) |
18 | | - return AnyType(TypeOfAny.from_error) |
19 | | - ret = lhs.value + rhs.value |
20 | | - return LiteralType(ret, fallback=ctx.api.named_generic_type('builtins.int', [])) |
| 10 | +def type_radd(ctx: MethodContext) -> Type: |
| 11 | + return LiteralType(7, fallback=ctx.api.named_generic_type('builtins.int', [])) |
21 | 12 |
|
22 | 13 |
|
23 | 14 | class TestPlugin(Plugin): |
24 | | - def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | None: |
25 | 15 |
|
| 16 | + def get_method_hook(self, fullname: str) -> Optional[Callable[[MethodContext], Type]]: |
26 | 17 | if fullname == 'builtins.int.__add__': |
27 | 18 | return type_add |
28 | 19 | if fullname == 'builtins.int.__radd__': |
|
0 commit comments