-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
In string formatting, a print-f style format specifier can have its amount and precision formatted by variable value through use of star asterik(%*s).
In cformat_bytes and cformat_string, through try_update_quantity_from_tuple, try_update_quantity_from_element is used to update quantity if possible, but it makes the assumption that its behavior should be the same regardless of the sign value of the given element.
if let Some(i) = width_obj.payload::<PyInt>() {
let i = i.try_to_primitive::<i32>(vm)?.unsigned_abs();
Ok(CFormatQuantity::Amount(i as usize))
}
However, that assumption is false, as an amount can be preceded by a negative sign, and it should make the resulting string left adjusted, according to format specifier rule.
https://docs.python.org/3/library/stdtypes.html#old-string-formatting
assert('%*s' % (-5, 'abc') == 'abc ')
This issue makes this test to fail.
I think this issue can be resolved by checking the sign of the element and adding the minus sign accordingly.
I'm working on the fix at the moment.