@@ -1304,16 +1304,17 @@ fn do_cformat(
1304
1304
. filter ( |( _, part) | CFormatPart :: is_specifier ( part) )
1305
1305
. all ( |( _, part) | CFormatPart :: has_key ( part) ) ;
1306
1306
1307
- let values_obj = if mapping_required {
1307
+ let values = if mapping_required {
1308
1308
if !objtype:: isinstance ( & values_obj, & vm. ctx . dict_type ( ) ) {
1309
1309
return Err ( vm. new_type_error ( "format requires a mapping" . to_string ( ) ) ) ;
1310
1310
}
1311
1311
values_obj. clone ( )
1312
1312
} else {
1313
- // check for only literal parts, in which case only empty tuple is allowed
1314
- if 0 == num_specifiers
1315
- && ( !objtype:: isinstance ( & values_obj, & vm. ctx . tuple_type ( ) )
1316
- || !objtuple:: get_value ( & values_obj) . is_empty ( ) )
1313
+ // check for only literal parts, in which case only dict or empty tuple is allowed
1314
+ if num_specifiers == 0
1315
+ && !( objtype:: isinstance ( & values_obj, & vm. ctx . tuple_type )
1316
+ && objtuple:: get_value ( & values_obj) . is_empty ( ) )
1317
+ && !objtype:: isinstance ( & values_obj, & vm. ctx . dict_type )
1317
1318
{
1318
1319
return Err ( vm. new_type_error (
1319
1320
"not all arguments converted during string formatting" . to_string ( ) ,
@@ -1336,12 +1337,11 @@ fn do_cformat(
1336
1337
let obj: PyObjectRef = match & format_spec. mapping_key {
1337
1338
Some ( key) => {
1338
1339
// TODO: change the KeyError message to match the one in cpython
1339
- call_getitem ( vm, & values_obj , & vm. ctx . new_str ( key. to_string ( ) ) ) ?
1340
+ call_getitem ( vm, & values , & vm. ctx . new_str ( key. to_string ( ) ) ) ?
1340
1341
}
1341
1342
None => {
1342
- let mut elements = objtuple:: get_value ( & values_obj)
1343
- . into_iter ( )
1344
- . skip ( tuple_index) ;
1343
+ let mut elements =
1344
+ objtuple:: get_value ( & values) . into_iter ( ) . skip ( tuple_index) ;
1345
1345
1346
1346
tuple_index = try_update_quantity_from_tuple (
1347
1347
vm,
@@ -1375,11 +1375,12 @@ fn do_cformat(
1375
1375
}
1376
1376
1377
1377
// check that all arguments were converted
1378
- if !mapping_required
1379
- && objtuple:: get_value ( & values_obj )
1378
+ if ( !mapping_required
1379
+ && objtuple:: get_value ( & values )
1380
1380
. into_iter ( )
1381
1381
. nth ( tuple_index)
1382
- . is_some ( )
1382
+ . is_some ( ) )
1383
+ && !objtype:: isinstance ( & values_obj, & vm. ctx . dict_type )
1383
1384
{
1384
1385
return Err (
1385
1386
vm. new_type_error ( "not all arguments converted during string formatting" . to_string ( ) )
0 commit comments