ikamensh / flynt

A tool to automatically convert old string literal formatting to f-strings
MIT License
687 stars 33 forks source link

Issue with multiple formatting on a single line #19

Closed browniebroke closed 5 years ago

browniebroke commented 5 years ago

We use openpyxl to generate some Excel reports and it has an unsual syntax, but completely logical in Excel land, that lets you select a subset of a sheet in a workbook with something like sheet['A1': 'C1'].

We use this syntax in a loop, where we use the index of the loop to format the string with number in it. Essentially, we do something like this:

from openpyxl.workbook import Workbook

wb = Workbook()
sheet = wb.active
i = 3
sheet['B{}'.format(i) : 'E{}'.format(i)]

The result we are getting when running Flynt is that the last line is duplicated:

sheet[f'B{i}' : 'E{}'.format(i)]
sheet['B{}'.format(i) : f'E{i}']

I'll see if I can isolate a use case that doesn't involve openpyxl, but in the meantime I thought I report it.

Thanks for this library!

ikamensh commented 5 years ago

This issue occurs in general when there are two conversions on a single line. Working on a fix.

browniebroke commented 5 years ago

Ah yes, this reproduces the problem too:

'{}'.format(3) + '{}'.format(5)
ikamensh commented 5 years ago

Fixed in v. 0.25 - now on PyPI. pip install --upgrade flynt for the newest version :)

browniebroke commented 5 years ago

Amazing, thanks! Will give it a go.