ikamensh / flynt

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

Transform concatenation does not work with "--string" #162

Closed EmmaJaneBonestell closed 1 year ago

EmmaJaneBonestell commented 1 year ago

Version/Dist information: Python 3.10.6 Bash v5.1.16(1)-release Ubuntu 22.04 x86_64

Expected behavior is achieved when reading from a python file. cat test.py:

#!/bin/env python
test_string = 'This' + '  ' + 'may ' + ' ' +  'not' + ' ' + 'work'

flynt -tc t.py:

test_string = f"This may not work"

flynt -tc --string "test_string = 'This' + ' ' + 'may' + ' ' + 'not' + ' ' + 'work'"

Expected result:

test_string = f"This may not work"

Actual result:

test_string = 'This' + ' ' + 'may' + ' ' + 'not' + ' ' + 'work'

Flynt does not report any errors or missed opportunities. It is simply not recognized. Passing it in from an array, using < <(...) , with escaped double quotes, etc., still does not produce the expected behavior.

akx commented 1 year ago

This will be fixed (in a roundabout way) by #161, whereafter you can do

echo "test_string = 'This' + ' ' + 'may' + ' ' + 'not' + ' ' + 'work'" | flynt -tc -
EmmaJaneBonestell commented 1 year ago

@akx For me, your PR #161 seems to have broken string concatenation. Your given example does not fix it on my machine, and concatenations in files no longer works either. It curiously does pass the test suite, but any manual usage fails.

akx commented 1 year ago

161 hasn't been merged or published yet, and all tests in that PR work...? Do you have repro steps to share?

akx commented 1 year ago

@EmmaJaneBonestell Ah, turns out I had broken that feature for the CLI back in #155, my bad. #163 fixes that and this issue.

EmmaJaneBonestell commented 1 year ago

@akx Installing from source, I can confirm that #163 fixed it. Thanks.