8000 gh-117797: Improve `test_descr.test_not_implemented` by sobolevn · Pull Request #117798 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117797: Improve test_descr.test_not_implemented #117798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-117797: Improve test_descr.test_not_implemented
  • Loading branch information
sobolevn committed Apr 12, 2024
commit 7ac3ebf4f8ba0914c62d73b5b3b5a85c1a3c79be
21 changes: 14 additions & 7 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4594,18 +4594,16 @@ def test_special_unbound_method_types(self):
def test_not_implemented(self):
# Testing NotImplemented...
# all binary methods should be able to return a NotImplemented
import operator

def specialmethod(self, other):
return NotImplemented

def check(expr, x, y):
try:
exec(expr, {'x': x, 'y': y, 'operator': operator})
except TypeError:
pass
else:
self.fail("no TypeError from %r" % (expr,))
with (
self.subTest(expr=expr, x=x, y=y),
self.assertRaises(TypeError)
):
exec(expr, {'x': x, 'y': y})

N1 = sys.maxsize + 1 # might trigger OverflowErrors instead of
# TypeErrors
Expand All @@ -4632,6 +4630,15 @@ def check(expr, x, y):
check(expr, a, a)
check(expr, a, N1)
check(expr, a, N2)
B = type('B', (), {rname: specialmethod})
b = B()
check(expr, b, b)
check(expr, a, b)
check(expr, b, a)
check(expr, b, N1)
check(expr, b, N2)
check(expr, N1, b)
check(expr, N2, b)
if iexpr:
check(iexpr, a, a)
check(iexpr, a, N1)
Expand Down
0