Format strings with complex forrmat specifiers are not unparsed correctly
Closed this issue · 4 comments
cyrus- commented
In the description of PEP 498, there is an example of a format specifier that itself contains interpolated values:
https://www.python.org/dev/peps/pep-0498/#format-specifiers
>>> width = 10
>>> precision = 4
>>> value = decimal.Decimal('12.34567')
>>> f'result: {value:{width}.{precision}}'
The unparse method doesn't seem to handle this well:
>>> astunparse.unparse(ast.parse("f'result: {value:{width}.{precision}}'"))
"\nf'''result: {value:f'''{width}.{precision}'''}'''\n"
Notice that the part after value:
is not bare but rather inside a format string, which isn't valid. The correct behavior should be:
>>> astunparse.unparse(ast.parse("f'result: {value:{width}.{precision}}'"))
"\nf'''result: {value:{width}.{precision}}'''\n"
cyrus- commented
If this is a problem with the upstream code that astunparse is based on, I'd be happy to file the bug elsewhere -- just let me know where it should go.
cyrus- commented
Just checked it out, doesn't seem to fix the problem in this issue...
simonpercivall commented
This is (should now be) fixed in v1.6.0. (Please reopen if I missed something.)