Skip to content

Commit a3fbf8f

Browse files
committed
okay it should pass now
1 parent ac4d0f6 commit a3fbf8f

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

test-data/unit/plugins/magic_method.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
11
from mypy.types import LiteralType, AnyType, TypeOfAny, Type
22
from mypy.plugin import Plugin, MethodContext
3-
from typing import Callable
3+
from typing import Callable, Optional
44

55
# 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)
88
return AnyType(TypeOfAny.from_error)
99

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', []))
2112

2213

2314
class TestPlugin(Plugin):
24-
def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | None:
2515

16+
def get_method_hook(self, fullname: str) -> Optional[Callable[[MethodContext], Type]]:
2617
if fullname == 'builtins.int.__add__':
2718
return type_add
2819
if fullname == 'builtins.int.__radd__':

0 commit comments

Comments
 (0)