@@ -142,6 +142,7 @@ fn generate_class_def(
142
142
name : & str ,
143
143
module_name : Option < & str > ,
144
144
base : Option < String > ,
145
+ metaclass : Option < String > ,
145
146
attrs : & [ Attribute ] ,
146
147
) -> std:: result:: Result < TokenStream , Diagnostic > {
147
148
let doc = if let Some ( doc) = attrs. doc ( ) {
@@ -175,20 +176,31 @@ fn generate_class_def(
175
176
)
176
177
. into ( ) ) ;
177
178
}
178
- let base = base. map ( |name| Ident :: new ( & name, ident. span ( ) ) ) ;
179
-
180
179
let base_class = if is_pystruct {
181
180
quote ! {
182
181
fn static_baseclass( ) -> & ' static :: rustpython_vm:: builtins:: PyTypeRef {
183
182
use rustpython_vm:: StaticType ;
184
183
rustpython_vm:: builtins:: PyTuple :: static_type( )
185
184
}
186
185
}
187
- } else if let Some ( base) = base {
186
+ } else if let Some ( typ) = base {
187
+ let typ = Ident :: new ( & typ, ident. span ( ) ) ;
188
188
quote ! {
189
189
fn static_baseclass( ) -> & ' static :: rustpython_vm:: builtins:: PyTypeRef {
190
190
use rustpython_vm:: StaticType ;
191
- #base:: static_type( )
191
+ #typ:: static_type( )
192
+ }
193
+ }
194
+ } else {
195
+ quote ! ( )
196
+ } ;
197
+
198
+ let meta_class = if let Some ( typ) = metaclass {
199
+ let typ = Ident :: new ( & typ, ident. span ( ) ) ;
200
+ quote ! {
201
+ fn static_metaclass( ) -> & ' static :: rustpython_vm:: builtins:: PyTypeRef {
202
+ use rustpython_vm:: StaticType ;
203
+ #typ:: static_type( )
192
204
}
193
205
}
194
206
} else {
@@ -211,6 +223,8 @@ fn generate_class_def(
211
223
& CELL
212
224
}
213
225
226
+ #meta_class
227
+
214
228
#base_class
215
229
}
216
230
} ;
@@ -227,7 +241,15 @@ pub(crate) fn impl_pyclass(
227
241
let class_name = class_meta. class_name ( ) ?;
228
242
let module_name = class_meta. module ( ) ?;
229
243
let base = class_meta. base ( ) ?;
230
- let class_def = generate_class_def ( ident, & class_name, module_name. as_deref ( ) , base, attrs) ?;
244
+ let metaclass = class_meta. metaclass ( ) ?;
245
+ let class_def = generate_class_def (
246
+ ident,
247
+ & class_name,
248
+ module_name. as_deref ( ) ,
249
+ base,
250
+ metaclass,
251
+ attrs,
252
+ ) ?;
231
253
232
254
let ret = quote ! {
233
255
#item
0 commit comments