black
black copied to clipboard
Black 23.9.1 reformat already clean code expression and creates a line too long
Describe the bug
Black 23.9.1 reformat already clean but complex code expression and creates a line too long. The original expression does not have lines longer than 79 characters. But black reformat it and creates a line of 94 characters.
To Reproduce
Create a file named bug.py with the following code :
if True:
if True:
if True:
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr = (
abcdefghijklmnopqrstuvwxyzabcd
| (
# Blablablablablablablablablablablablablablablablablablabl
# blablablablablablablablablablablablablabla - (
abcdefghijk - (
abcdefghijklmnopqrstuvwxyzabcd
| abcdefghijklmnopqrstuvwxyza
)
)
)
And run black with these arguments:
$ black --check --diff bug.py
The resulting display is:
--- bug.py 2023-10-06 10:06:30.801786+00:00
+++ bug.py 2023-10-06 10:12:04.476521+00:00
@@ -1,15 +1,9 @@
if True:
if True:
if True:
- abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr = (
- abcdefghijklmnopqrstuvwxyzabcd
- | (
- # Blablablablablablablablablablablablablablablablablablabl
- # blablablablablablablablablablablablablabla - (
- abcdefghijk - (
- abcdefghijklmnopqrstuvwxyzabcd
- | abcdefghijklmnopqrstuvwxyza
- )
- )
+ abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr = abcdefghijklmnopqrstuvwxyzabcd | (
+ # Blablablablablablablablablablablablablablablablablablabl
+ # blablablablablablablablablablablablablabla - (
+ abcdefghijk
+ - (abcdefghijklmnopqrstuvwxyzabcd | abcdefghijklmnopqrstuvwxyza)
)
-
would reformat bug.py
Oh no! 💥 💔 💥
1 file would be reformatted.
Expected behavior
Black should keep it as is or at least propose something that does not go beyond the default line length.
Environment
- Black's version: black, 23.9.1 (compiled: yes)
- OS and Python version: Ubuntu 23.04 Python (CPython) 3.11.4
Additional context
Hi @LLyaudet, I want to work on this issue. Could you assign it to me? Thanks
Hi @tienthai0205 :) Thanks for wanting to solve it. Unfortunately, I am not among the maintainers of this repo and I do not have the rights to assign issues. Maybe @JelleZijlstra can help :)
Feel free to send a PR with a proposed solution.