3

Before:

value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

After running black --line-length 80 file.py: (long string remains unchanged)

value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

Expected behavior (something close to this):

value = """aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj
        sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj
        dsklfj dsklfj dsklfj dsklfj dsklfj dkl"""

or

value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj" \
        "sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj" \
        "dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

[Q] Long string remains unchanged, can python-black convert them into multine? If not, is there any other tool to accomplish it?

alper
  • 2,919
  • 9
  • 53
  • 102
  • 3
    I suggest you raise an issue on black github – Chris_Rands Jul 01 '20 at 14:07
  • @Chris_Rands Done (https://github.com/psf/black/issues/1528). Since it is a global issue I think it may be useful to solve or have a documentation for this. Should I delete my question here? – alper Jul 01 '20 at 14:34
  • 1
    @Chris_Rands Done (https://github.com/psf/black/issues/1528) answered: `Black already does wrap long string literals due to #1132(https://github.com/psf/black/pull/1132). We haven't released a new version yet though, so it only lives in the master branch of this repo.`. Should I delete my question? – alper Jul 01 '20 at 14:49
  • You could self-answer the question – Chris_Rands Jul 01 '20 at 16:00

1 Answers1

3

From the following opened github issue:

Black already does wrap long string literals due to #1132. We haven't released a new version yet though, so it only lives in the master branch of this repo.

(black) richard-26@ubuntu-laptop:~/programming/black$ black test.py -l
80 --color --diff
--- test.py   2020-07-01 14:36:24.700946 +0000
+++ test.py   2020-07-01 14:36:38.436792 +0000 @@ -1 +1,4 @@
-value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

+value = (
+    "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl"
+    " jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"
+) 
would reformat test.py 
All done! ✨  ✨ 
1 file would be reformatted. ```
alper
  • 2,919
  • 9
  • 53
  • 102