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

Treat double-width unicode characters #1154

Closed
hallazzang opened this issue Nov 12, 2019 · 1 comment
Closed

Treat double-width unicode characters #1154

hallazzang opened this issue Nov 12, 2019 · 1 comment
Labels
T: style What do we want Blackened code to look like?

Comments

@hallazzang
Copy link

Describe the style change
Black currently does not handle double-width characters(i.e. CJK characters) different from single-width characters.
This leads black to make some lines too long to see in small(~88 characters width) window.
Please check the example below.

Examples in the current Black style
Consider this input:

foo = (
    ("aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb"),
    ("안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요"),
)

If I run black --diff main.py, then I get this result:

@@ -1,4 +1,15 @@
 foo = (
-    ("aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb", "aaaaabbbbb"),
+    (
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+        "aaaaabbbbb",
+    ),
     ("안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요"),
 )

Desired style
I want black to style my code like this:

foo = (
    (
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
        "aaaaabbbbb",
    ),
    (
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
        "안녕하세요",
    ),
)

But black prevents it, rather does this:

@@ -8,17 +8,8 @@
         "aaaaabbbbb",
         "aaaaabbbbb",
         "aaaaabbbbb",
         "aaaaabbbbb",
     ),
-    (
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-        "안녕하세요",
-    ),
+    ("안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요", "안녕하세요",),
 )

Additional context

$ black --version
black, version 19.10b0
@hallazzang hallazzang added the T: style What do we want Blackened code to look like? label Nov 12, 2019
@ichard26
Copy link
Collaborator

#1197 is a duplicate of this issue, but it has more context and discussion, so closing this in favour of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants