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

Black removes indentation in multi-line dict with multi-line value #1758

Closed
gsamaras opened this issue Oct 9, 2020 · 3 comments
Closed

Black removes indentation in multi-line dict with multi-line value #1758

gsamaras opened this issue Oct 9, 2020 · 3 comments
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@gsamaras
Copy link

gsamaras commented Oct 9, 2020

Describe the bug

A code snippet is worth a thousand words.

To Reproduce Steps to reproduce the behavior:

It removes the indentation from the second line of a two line long value string:

mydict = {
    'key0': 'value0',
    'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue'
            'value1'
}

to:

mydict = {
    'key0': 'value0',
    'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue'
    'value1',
}

Demo

Expected behavior
Enforce/keep the 2nd line of value to start its indentation from same column as 1st line of value.

The wrapped element, which should follow the guidance in PEP8 -- Style Guide for Python Code#indentation, is the value.

Environment (please complete the following information):

  • Version: master
  • OS and Python version: macOS, Python 3.6.x

Additional context

Stack Overflow: PEP8 multi-line dict with multi-line value.

@gsamaras gsamaras added the T: bug Something isn't working label Oct 9, 2020
@textbook
Copy link

textbook commented Oct 9, 2020

Related: #620

@JelleZijlstra
Copy link
Collaborator

The --experimental-string-processing flag fixes this example:

 % black --experimental-string-processing --diff issue1758.py
--- issue1758.py	2021-05-29 02:55:21.422319 +0000
+++ issue1758.py	2021-05-29 02:55:32.992736 +0000
@@ -1,5 +1,6 @@
 mydict = {
-    'key0': 'value0',
-    'key1': 'long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continue'
-            'value1'
+    "key0": "value0",
+    "key1": (
+        "long-two-lines-string-value1-does-not-fit-in-one-line-has-to-continuevalue1"
+    ),
 }
would reformat issue1758.py
All done! ✨ 🍰 ✨
1 file would be reformatted.

@JelleZijlstra JelleZijlstra added T: style What do we want Blackened code to look like? F: linebreak How should we split up lines? and removed T: bug Something isn't working labels May 30, 2021
@JelleZijlstra
Copy link
Collaborator

Duplicate of #620

@JelleZijlstra JelleZijlstra marked this as a duplicate of #620 Jan 29, 2022
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants