ikamensh / flynt

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

--transform-concats trips flynt on some code #173

Open PiRK opened 1 year ago

PiRK commented 1 year ago

Flynt does not seem to be able to process this file when option --transform-concats is set: https://reviews.bitcoinabc.org/source/bitcoin-abc/browse/master/test/functional/test_runner.py

I narrowed the issue down to these lines:

individual_tests = [
    re.sub(r"\.py$", "", test) + ".py" for test in tests if not test.endswith('*')]

Running flynt --stdout --transform-concats file.py or cat file.py | flynt --transform-concats - on a file that contains this causes an empty output. Running flynt --transform-concats file.py on such a file causes the file to be untouched, even if it contains "%" formatted strings to be updated.

A sample to reproduce the issue:

import re

tests = [
    "a.py",
    "b.py",
    "c*",
]

spam0 = "%s %s" % ("foo", "bar")

individual_tests = [
    re.sub(r"\.py$", "", test) + ".py" for test in tests if not test.endswith('*')]

spam = "%s %s" % ("foo", "bar")