Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in behaviour with %-formatted aligned string with tuple interpreted vs compiled #3476

LordAro opened this issue Mar 31, 2020 · 2 comments


Copy link

LordAro commented Mar 31, 2020

With the following testcase:

print("str: '%08s'" % (""))
print("str: '%08s'" % ("",))

When run with python (3.8):

 $ python3
str: '        '
str: '        '

When compiled with cython (0.29.15):

 $ cython --embed -3 && gcc foo.c -lpython3.8 -o foo
 $ ./foo
str: '        '
Traceback (most recent call last):
  File "", line 2, in init foo
    print("str: '%08s'" % ("",))
ValueError: '=' alignment not allowed in string format specifier

Something to do with the tuple is making it very unhappy...
Possibly related to #3092 ?

Copy link

scoder commented Mar 31, 2020

Yes, related to #3092.

The difference between the two lines is that only the tuple case is being optimised (into an f-string), because the single-argument-non-tuple case is not easy to optimise (it might still receive a tuple at runtime, especially since the real type is usually unknown and the argument is almost never a constant as in your simple example).

Both seem easy to fix. PR welcome.
Worst case, the f-string optimisation could be disabled for these formats. Or preferably converted correctly.

Copy link

nanlliu commented Apr 3, 2020

is it something a beginner can do? any help tho? can I work on this? if possible, I would love to work on both issues! much appreciated! @scoder

@scoder scoder closed this as completed in dcf6b82 May 9, 2020
@scoder scoder added this to the 0.29.18 milestone May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants