Skip to content

Commit 7ac3ebf

Browse files
committed
gh-117797: Improve test_descr.test_not_implemented
1 parent fd259fd commit 7ac3ebf

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Lib/test/test_descr.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4594,18 +4594,16 @@ def test_special_unbound_method_types(self):
45944594
def test_not_implemented(self):
45954595
# Testing NotImplemented...
45964596
# all binary methods should be able to return a NotImplemented
4597-
import operator
45984597

45994598
def specialmethod(self, other):
46004599
return NotImplemented
46014600

46024601
def check(expr, x, y):
4603-
try:
4604-
exec(expr, {'x': x, 'y': y, 'operator': operator})
4605-
except TypeError:
4606-
pass
4607-
else:
4608-
self.fail("no TypeError from %r" % (expr,))
4602+
with (
4603+
self.subTest(expr=expr, x=x, y=y),
4604+
self.assertRaises(TypeError)
4605+
):
4606+
exec(expr, {'x': x, 'y': y})
46094607

46104608
N1 = sys.maxsize + 1 # might trigger OverflowErrors instead of
46114609
# TypeErrors
@@ -4632,6 +4630,15 @@ def check(expr, x, y):
46324630
check(expr, a, a)
46334631
check(expr, a, N1)
46344632
check(expr, a, N2)
4633+
B = type('B', (), {rname: specialmethod})
4634+
b = B()
4635+
check(expr, b, b)
4636+
check(expr, a, b)
4637+
check(expr, b, a)
4638+
check(expr, b, N1)
4639+
check(expr, b, N2)
4640+
check(expr, N1, b)
4641+
check(expr, N2, b)
46354642
if iexpr:
46364643
check(iexpr, a, a)
46374644
check(iexpr, a, N1)

0 commit comments

Comments
 (0)