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

Long string remains unchanged, can black make them in multine representation [help] #1528

Closed
avatar-lavventura opened this issue Jul 1, 2020 · 7 comments
Labels
T: enhancement New feature or request

Comments

@avatar-lavventura
Copy link

avatar-lavventura commented Jul 1, 2020

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?

@avatar-lavventura avatar-lavventura added the T: enhancement New feature or request label Jul 1, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Jul 1, 2020

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.

@avatar-lavventura
Copy link
Author

avatar-lavventura commented Jul 1, 2020

@ichard26 Thats great! //How could I use the master version?

Could I do with following line:

pip install https://github.com/psf/black/master.zip

@cooperlees
Copy link
Collaborator

pip install git+git://github.com/psf/black

@avatar-lavventura
Copy link
Author

@cooperlees : Also what should I write into .pre-commit-config.yaml. I updated as but it did not recognize it as a valid rev:

❯ black --version
black, version 19.10b1.dev123+g2471b92
-   repo: https://github.com/psf/black
    rev: 19.10b1.dev123+g2471b92
    hooks:
      - id: black
        name: black

@ichard26
Copy link
Collaborator

ichard26 commented Jul 1, 2020

Black has it own custom version output that isn't compatible with git so referencing the exact commit is necessary:

-   repo: https://github.com/psf/black
    rev: 2471b9256d9d9dfea1124d20072201693b9b0865
    hooks:
      - id: black
        name: black

Please note that if you update your pip installed installation of Black. it will be out of sync with your pre-commit version of Black.

@xrisk
Copy link
Contributor

xrisk commented Aug 6, 2021

Has this been disabled, or is there a regression? I can't get

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

to wrap on head.


Never mind, it appears this feature is gated behind the hidden flag --experimental-string-processing.

@ichard26
Copy link
Collaborator

ichard26 commented Aug 6, 2021

Yeah, we had to hide it under a flag because it was causing way too many crashes. IIRC all of 'em have been fixed and what remains is a significant performance penalty under specific conditions with ESP enabled. See also #2188.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants