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

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

Open
PiRK opened this issue Apr 5, 2023 · 0 comments
Open

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

PiRK opened this issue Apr 5, 2023 · 0 comments

Comments

@PiRK
Copy link
Contributor

PiRK commented Apr 5, 2023

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")

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this issue Apr 5, 2023
Summary:
See ikamensh/flynt#173

The linter will still be able to convert "%"-formatted strings  and `"{}".format(` occurences to f-strings.
It will no longer simplify string concatenations.

Test Plan:
Touch test_runner.py and make sure `arc lint` does not clear the file.

Add actual lines that flynt will update, and check that the changes from `arc lint` is as expected. E.g:
```
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index 38ac427eeb..079079e3bb 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -163,6 +163,9 @@ class TestCase:
         self.test_num = test_num
         self.failfast_event = failfast_event
         self.flags = flags
+        a = "%s " % "toto"
+        b = "{}".format(a)
+        print(a + b)

     def run(self):
         if self.failfast_event.is_set():
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant