py/objstr: Support '{:08}'.format("Jan") like Python 3.10.
The new test has an .exp file, because it is not compatible with Python 3.9 and lower. See CPython version of the issue at https://bugs.python.org/issue27772 Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit is contained in:
parent
5e506567a3
commit
037b2c72a1
@ -1163,7 +1163,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
|
|||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
if (*s == '0') {
|
if (*s == '0') {
|
||||||
if (!align) {
|
if (!align && arg_looks_numeric(arg)) {
|
||||||
align = '=';
|
align = '=';
|
||||||
}
|
}
|
||||||
if (!fill) {
|
if (!fill) {
|
||||||
|
9
tests/basics/string_format_cp310.py
Normal file
9
tests/basics/string_format_cp310.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Python 3.10+ functionality test for {} format string
|
||||||
|
|
||||||
|
def test(fmt, *args):
|
||||||
|
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
|
||||||
|
|
||||||
|
test("{:0s}", "ab")
|
||||||
|
test("{:06s}", "ab")
|
||||||
|
test("{:<06s}", "ab")
|
||||||
|
test("{:>06s}", "ab")
|
4
tests/basics/string_format_cp310.py.exp
Normal file
4
tests/basics/string_format_cp310.py.exp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{:0s} >ab<
|
||||||
|
{:06s} >ab0000<
|
||||||
|
{:<06s} >ab0000<
|
||||||
|
{:>06s} >0000ab<
|
@ -1,7 +1,7 @@
|
|||||||
# tests for errors in {} format string
|
# tests for errors in {} format string
|
||||||
|
|
||||||
try:
|
try:
|
||||||
'{0:0}'.format('zzz')
|
'{0:=}'.format('zzz')
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
print('ValueError')
|
print('ValueError')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user