@@ -84,34 +84,37 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
84
84
85
85
// Extract interface types and base class types.
86
86
var interfaces = new List < Type > ( ) ;
87
- var baseType = new List < ClassBase > ( ) ;
88
87
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 > ( ) ;
90
91
91
- for ( uint i = 0 ; i < cnt ; i ++ )
92
+ var baseClassCount = Runtime . PyTuple_Size ( bases ) ;
93
+
94
+ for ( nint i = 0 ; i < baseClassCount ; i ++ )
92
95
{
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 )
96
99
{
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 ) ;
100
103
}
101
104
}
102
105
// if the base type count is 0, there might still be interfaces to implement.
103
- if ( baseType . Count == 0 )
106
+ if ( baseTypes . Count == 0 )
104
107
{
105
- baseType . Add ( new ClassBase ( typeof ( object ) ) ) ;
108
+ baseTypes . Add ( new ClassBase ( typeof ( object ) ) ) ;
106
109
}
107
110
108
111
// Multiple inheritance is not supported, unless the other types are interfaces
109
- if ( baseType . Count > 1 )
112
+ if ( baseTypes . Count > 1 )
110
113
{
111
114
return Exceptions . RaiseTypeError ( "cannot use multiple inheritance with managed classes" ) ;
112
115
}
113
116
114
- var cb = baseType [ 0 ] ;
117
+ var cb = baseTypes [ 0 ] ;
115
118
try
116
119
{
117
120
if ( ! cb . CanSubclass ( ) )
@@ -140,7 +143,7 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args,
140
143
using var clsDict = new PyDict ( dict ) ;
141
144
if ( clsDict . HasKey ( "__assembly__" ) || clsDict . HasKey ( "__namespace__" ) )
142
145
{
143
- return TypeManager . CreateSubType ( name , baseType , interfaces , clsDict ) ;
146
+ return TypeManager . CreateSubType ( name , baseTypes [ 0 ] , interfaces , clsDict ) ;
144
147
}
145
148
}
146
149
0 commit comments