@@ -218,15 +218,40 @@ fn try_update_quantity_from_element(
218218 }
219219}
220220
221+ fn try_conversion_flag_from_tuple (
222+ vm : & VirtualMachine ,
223+ element : Option < & PyObjectRef > ,
224+ ) -> PyResult < CConversionFlags > {
225+ match element {
226+ Some ( width_obj) => {
227+ if let Some ( i) = width_obj. payload :: < PyInt > ( ) {
228+ let i = i. try_to_primitive :: < i32 > ( vm) ?;
229+ let flags = if i < 0 {
230+ CConversionFlags :: LEFT_ADJUST
231+ } else {
232+ CConversionFlags :: from_bits ( 0 ) . unwrap ( )
233+ } ;
234+ Ok ( flags)
235+ } else {
236+ Err ( vm. new_type_error ( "* wants int" . to_owned ( ) ) )
237+ }
238+ }
239+ None => Err ( vm. new_type_error ( "not enough arguments for format string" . to_owned ( ) ) ) ,
240+ }
241+ }
242+
221243fn try_update_quantity_from_tuple < ' a , I : Iterator < Item = & ' a PyObjectRef > > (
222244 vm : & VirtualMachine ,
223245 elements : & mut I ,
224246 q : & mut Option < CFormatQuantity > ,
247+ f : & mut CConversionFlags ,
225248) -> PyResult < ( ) > {
226249 let Some ( CFormatQuantity :: FromValuesTuple ) = q else {
227250 return Ok ( ( ) ) ;
228251 } ;
229- let quantity = try_update_quantity_from_element ( vm, elements. next ( ) ) ?;
252+ let element = elements. next ( ) ;
253+ f. insert ( try_conversion_flag_from_tuple ( vm, element) ?) ;
254+ let quantity = try_update_quantity_from_element ( vm, element) ?;
230255 * q = Some ( quantity) ;
231256 Ok ( ( ) )
232257}
@@ -322,7 +347,12 @@ pub(crate) fn cformat_bytes(
322347 match part {
323348 CFormatPart :: Literal ( literal) => result. append ( literal) ,
324349 CFormatPart :: Spec ( spec) => {
325- try_update_quantity_from_tuple ( vm, & mut value_iter, & mut spec. min_field_width ) ?;
350+ try_update_quantity_from_tuple (
351+ vm,
352+ & mut value_iter,
353+ & mut spec. min_field_width ,
354+ & mut spec. flags ,
355+ ) ?;
326356 try_update_precision_from_tuple ( vm, & mut value_iter, & mut spec. precision ) ?;
327357
328358 let value = match value_iter. next ( ) {
@@ -416,7 +446,12 @@ pub(crate) fn cformat_string(
416446 match part {
417447 CFormatPart :: Literal ( literal) => result. push_str ( literal) ,
418448 CFormatPart :: Spec ( spec) => {
419- try_update_quantity_from_tuple ( vm, & mut value_iter, & mut spec. min_field_width ) ?;
449+ try_update_quantity_from_tuple (
450+ vm,
451+ & mut value_iter,
452+ & mut spec. min_field_width ,
453+ & mut spec. flags ,
454+ ) ?;
420455 try_update_precision_from_tuple ( vm, & mut value_iter, & mut spec. precision ) ?;
421456
422457 let value = match value_iter. next ( ) {
0 commit comments