Skip to content

Commit 04e0d98

Browse files
committed
Add test case with final decorator
1 parent 8adbcbf commit 04e0d98

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mypyc/test-data/run-dunders.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,3 +937,31 @@ def test_errors() -> None:
937937
pow(ForwardNotImplemented(), Child(), 3) # type: ignore
938938
with assertRaises(TypeError, "unsupported operand type(s) for ** or pow(): 'ForwardModRequired' and 'int'"):
939939
ForwardModRequired()**3 # type: ignore
940+
941+
[case testDundersWithFinal]
942+
from typing import final
943+
class A:
944+
def __init__(self, x: int) -> None:
945+
self.x = x
946+
947+
def __add__(self, y: int) -> int:
948+
return self.x + y
949+
950+
def __lt__(self, x: 'A') -> bool:
951+
return self.x < x.x
952+
953+
@final
954+
class B(A):
955+
def __add__(self, y: int) -> int:
956+
return self.x + y + 1
957+
958+
def __lt__(self, x: 'A') -> bool:
959+
return self.x < x.x + 1
960+
961+
def test_final() -> None:
962+
a = A(5)
963+
b = B(5)
964+
assert a + 3 == 8
965+
assert b + 3 == 9
966+
assert (a < A(5)) is False
967+
assert (a < A(5)) is True

0 commit comments

Comments
 (0)