Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13c3597

Browse filesBrowse files
committed
gh-113212: Test supercheck error message
1 parent 0f7d134 commit 13c3597
Copy full SHA for 13c3597

File tree

1 file changed

+19
-0
lines changed
Filter options

1 file changed

+19
-0
lines changed

‎Lib/test/test_super.py

Copy file name to clipboardExpand all lines: Lib/test/test_super.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,25 @@ def method(self):
396396
with self.assertRaisesRegex(TypeError, "argument 1 must be a type"):
397397
C().method()
398398

399+
def test_supercheck_fail(self):
400+
class C:
401+
def method(self, type_, obj):
402+
return super(type_, obj).method()
403+
404+
c = C()
405+
err_msg = r"super\(type, obj\): obj \({} {}\) is not an instance or subtype of type \({}\)."
406+
cases = (
407+
(int, c, int.__name__, C.__name__, "instance of"),
408+
(C, list(), C.__name__, list.__name__, "instance of"), # obj is instance of type
409+
(C, list, C.__name__, list.__name__, "type"), # obj is type itself
410+
)
411+
412+
for type_, obj, type_str, obj_str, instance_or_type in cases:
413+
regex = err_msg.format(instance_or_type, obj_str, type_str)
414+
415+
with self.assertRaisesRegex(TypeError, regex):
416+
c.method(type_, obj)
417+
399418
def test_super___class__(self):
400419
class C:
401420
def method(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.