@@ -216,30 +216,8 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
216
216
format ! ( "`{}` is not a typed dictionary. Typed dictionary definitions may only extend other typed dictionaries." , bad. 0 . name( ) ) ,
217
217
) ;
218
218
}
219
- let typed_dict_metadata = if is_typed_dict {
220
- // Validate that only 'total' keyword is allowed for TypedDict and determine is_total
221
- let mut is_total = true ;
222
- for ( name, value) in & keywords {
223
- if name. as_str ( ) != "total" {
224
- self . error (
225
- errors,
226
- cls. range ( ) ,
227
- ErrorInfo :: Kind ( ErrorKind :: BadTypedDict ) ,
228
- format ! (
229
- "TypedDict does not support keyword argument `{}`" ,
230
- name. as_str( )
231
- ) ,
232
- ) ;
233
- } else if matches ! ( value, Type :: Literal ( Lit :: Bool ( false ) ) ) {
234
- is_total = false ;
235
- }
236
- }
237
- let fields =
238
- self . calculate_typed_dict_metadata_fields ( cls, & bases_with_metadata, is_total) ;
239
- Some ( TypedDictMetadata { fields } )
240
- } else {
241
- None
242
- } ;
219
+ let typed_dict_metadata =
220
+ self . typed_dict_metadata ( cls, & bases_with_metadata, & keywords, is_typed_dict, errors) ;
243
221
let base_metaclasses = bases_with_metadata
244
222
. iter ( )
245
223
. filter_map ( |( b, metadata) | metadata. metaclass ( ) . map ( |m| ( b. name ( ) , m) ) )
@@ -481,6 +459,40 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
481
459
} )
482
460
}
483
461
462
+ fn typed_dict_metadata (
463
+ & self ,
464
+ cls : & Class ,
465
+ bases_with_metadata : & [ ( Class , Arc < ClassMetadata > ) ] ,
466
+ keywords : & [ ( Name , Type ) ] ,
467
+ is_typed_dict : bool ,
468
+ errors : & ErrorCollector ,
469
+ ) -> Option < TypedDictMetadata > {
470
+ if is_typed_dict {
471
+ // Validate that only 'total' keyword is allowed for TypedDict and determine is_total
472
+ let mut is_total = true ;
473
+ for ( name, value) in keywords {
474
+ if name. as_str ( ) != "total" {
475
+ self . error (
476
+ errors,
477
+ cls. range ( ) ,
478
+ ErrorInfo :: Kind ( ErrorKind :: BadTypedDict ) ,
479
+ format ! (
480
+ "TypedDict does not support keyword argument `{}`" ,
481
+ name. as_str( )
482
+ ) ,
483
+ ) ;
484
+ } else if matches ! ( value, Type :: Literal ( Lit :: Bool ( false ) ) ) {
485
+ is_total = false ;
486
+ }
487
+ }
488
+ let fields =
489
+ self . calculate_typed_dict_metadata_fields ( cls, bases_with_metadata, is_total) ;
490
+ Some ( TypedDictMetadata { fields } )
491
+ } else {
492
+ None
493
+ }
494
+ }
495
+
484
496
fn enum_metadata (
485
497
& self ,
486
498
cls : & Class ,
0 commit comments