长字符串保持不变,python-black 可以将它们转换为 multine

Long string remains unchanged, can python-black convert them into multine

之前:

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

运行black --line-length 80 file.py后:(长串保持不变)

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

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

[Q] 长字符串不变,可以python-black 将它们转换成multine吗?如果没有,有没有其他工具可以完成?

从下面打开githubissue:

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. ```