@@ -396,6 +396,31 @@ def method(self):
396
396
with self .assertRaisesRegex (TypeError , "argument 1 must be a type" ):
397
397
C ().method ()
398
398
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 = (
406
+ r"super\(type, obj\): obj \({} {}\) is not "
407
+ r"an instance or subtype of type \({}\)."
408
+ )
409
+
410
+ cases = (
411
+ (int , c , int .__name__ , C .__name__ , "instance of" ),
412
+ (C , list (), C .__name__ , list .__name__ , "instance of" ), # obj is instance of type
413
+ (C , list , C .__name__ , list .__name__ , "type" ), # obj is type itself
414
+ )
415
+
416
+ for case in cases :
417
+ with self .subTest (case = case ):
418
+ type_ , obj , type_str , obj_str , instance_or_type = case
419
+ regex = err_msg .format (instance_or_type , obj_str , type_str )
420
+
421
+ with self .assertRaisesRegex (TypeError , regex ):
422
+ c .method (type_ , obj )
423
+
399
424
def test_super___class__ (self ):
400
425
class C :
401
426
def method (self ):
0 commit comments