@@ -84,34 +84,37 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
8484
8585 // Extract interface types and base class types.
8686 var interfaces = new List < Type > ( ) ;
87- var baseType = new List < ClassBase > ( ) ;
8887
89- var cnt = Runtime . PyTuple_GetSize ( bases ) ;
88+ // More than one base type case be declared, but an exception will be thrown
89+ // if more than one is a class/not an interface.
90+ var baseTypes = new List < ClassBase > ( ) ;
9091
91- for ( uint i = 0 ; i < cnt ; i ++ )
92+ var baseClassCount = Runtime . PyTuple_Size ( bases ) ;
93+
94+ for ( nint i = 0 ; i < baseClassCount ; i ++ )
9295 {
93- var base_type2 = Runtime . PyTuple_GetItem ( bases , ( int ) i ) ;
94- var cb2 = ( ClassBase ) GetManagedObject ( base_type2 ) ;
95- if ( cb2 != null )
96+ var baseTypeIt = Runtime . PyTuple_GetItem ( bases , ( int ) i ) ;
97+
98+ if ( GetManagedObject ( baseTypeIt ) is ClassBase classBaseIt )
9699 {
97- if ( cb2 . type . Valid && cb2 . type . Value . IsInterface )
98- interfaces . Add ( cb2 . type . Value ) ;
99- else baseType . Add ( cb2 ) ;
100+ if ( classBaseIt . type . Valid && classBaseIt . type . Value . IsInterface )
101+ interfaces . Add ( classBaseIt . type . Value ) ;
102+ else baseTypes . Add ( classBaseIt ) ;
100103 }
101104 }
102105 // if the base type count is 0, there might still be interfaces to implement.
103- if ( baseType . Count == 0 )
106+ if ( baseTypes . Count == 0 )
104107 {
105- baseType . Add ( new ClassBase ( typeof ( object ) ) ) ;
108+ baseTypes . Add ( new ClassBase ( typeof ( object ) ) ) ;
106109 }
107110
108111 // Multiple inheritance is not supported, unless the other types are interfaces
109- if ( baseType . Count > 1 )
112+ if ( baseTypes . Count > 1 )
110113 {
111114 return Exceptions . RaiseTypeError ( "cannot use multiple inheritance with managed classes" ) ;
112115 }
113116
114- var cb = baseType [ 0 ] ;
117+ var cb = baseTypes [ 0 ] ;
115118 try
116119 {
117120 if ( ! cb . CanSubclass ( ) )
@@ -140,7 +143,7 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
140143 using var clsDict = new PyDict ( dict ) ;
141144 if ( clsDict . HasKey ( "__assembly__" ) || clsDict . HasKey ( "__namespace__" ) )
142145 {
143- return TypeManager . CreateSubType ( name , baseType , interfaces , clsDict ) ;
146+ return TypeManager . CreateSubType ( name , baseTypes [ 0 ] , interfaces , clsDict ) ;
144147 }
145148 }
146149
0 commit comments