@@ -4920,6 +4920,75 @@ class B(Generic[S]): ...
49204920 class C (List [int ], B ): ...
49214921 self .assertEqual (C .__mro__ , (C , list , B , Generic , object ))
49224922
4923+ def test_multiple_inheritance_non_type_with___mro_entries__ (self ):
4924+ class GoodEntries :
4925+ def __mro_entries__ (self , bases ):
4926+ return (object ,)
4927+
4928+ class A (List [int ], GoodEntries ()): ...
4929+
4930+ self .assertEqual (A .__mro__ , (A , list , Generic , object ))
4931+
4932+ def test_multiple_inheritance_non_type_without___mro_entries__ (self ):
4933+ # Error should be from the type machinery, not from typing.py
4934+ with self .assertRaisesRegex (TypeError , r"^bases must be types" ):
4935+ class A (List [int ], object ()): ...
4936+
4937+ def test_multiple_inheritance_non_type_bad___mro_entries__ (self ):
4938+ class BadEntries :
4939+ def __mro_entries__ (self , bases ):
4940+ return None
4941+
4942+ # Error should be from the type machinery, not from typing.py
4943+ with self .assertRaisesRegex (
4944+ TypeError ,
4945+ r"^__mro_entries__ must return a tuple" ,
4946+ ):
4947+ class A (List [int ], BadEntries ()): ...
4948+
4949+ def test_multiple_inheritance___mro_entries___returns_non_type (self ):
4950+ class BadEntries :
4951+ def __mro_entries__ (self , bases ):
4952+ return (object (),)
4953+
4954+ # Error should be from the type machinery, not from typing.py
4955+ with self .assertRaisesRegex (
4956+ TypeError ,
4957+ r"^bases must be types" ,
4958+ ):
4959+ class A (List [int ], BadEntries ()): ...
4960+
4961+ def test_multiple_inheritance_with_genericalias (self ):
4962+ class A (typing .Sized , list [int ]): ...
4963+
4964+ self .assertEqual (
4965+ A .__mro__ ,
4966+ (A , collections .abc .Sized , Generic , list , object ),
4967+ )
4968+
4969+ def test_multiple_inheritance_with_genericalias_2 (self ):
4970+ T = TypeVar ("T" )
4971+
4972+ class BaseSeq (typing .Sequence [T ]): ...
4973+ class MySeq (List [T ], BaseSeq [T ]): ...
4974+
4975+ self .assertEqual (
4976+ MySeq .__mro__ ,
4977+ (
4978+ MySeq ,
4979+ list ,
4980+ BaseSeq ,
4981+ collections .abc .Sequence ,
4982+ collections .abc .Reversible ,
4983+ collections .abc .Collection ,
4984+ collections .abc .Sized ,
4985+ collections .abc .Iterable ,
4986+ collections .abc .Container ,
4987+ Generic ,
4988+ object ,
4989+ ),
4990+ )
4991+
49234992 def test_init_subclass_super_called (self ):
49244993 class FinalException (Exception ):
49254994 pass
0 commit comments