8000 py/objstr: Support '{:08}'.format("Jan") like Python 3.10. · micropython/micropython@037b2c7 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 037b2c7

Browse files
jeplerdpgeorge
authored andcommitted
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>
1 parent 5e50656 commit 037b2c7

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

py/objstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar
11631163
s++;
11641164
}
11651165
if (*s == '0') {
1166-
if (!align) {
1166+
if (!align && arg_looks_numeric(arg)) {
11671167
align = '=';
11681168
}
11691169
if (!fill) {

tests/basics/string_format_cp310.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Python 3.10+ functionality test for {} format string
2+
3+
def test(fmt, *args):
4+
print('{:8s}'.format(fmt) + '>' + fmt.format(*args) + '<')
5+
6+
test("{:0s}", "ab")
7+
test("{:06s}", "ab")
8+
test("{:<06s}", "ab")
9+
test("{:>06s}", "ab")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:0s} >ab<
2+
{:06s} >ab0000<
3+
{:<06s} >ab0000<
4+
{:>06s} >0000ab<

tests/basics/string_format_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# tests for errors in {} format string
22

33
try:
4-
'{0:0}'.format('zzz')
4+
'{0:=}'.format('zzz')
55
except (ValueError):
66
print('ValueError')
77

0 commit comments

Comments
 (0)
0