Black incorrectly formatting code - output has lines with more than 88 characters
See original GitHub issueDescribe the bug Black is failing to format a Python snippet to conform with its own rules; in particular, the default 88 character limit is breached.
To Reproduce
- Create a file with this Python code:
exclude_because_before = exclude_trips_before is not None and trip_stop_time.get_time().timestamp() <= current_time - float(
exclude_trips_before
)
- Run Black on it with no arguments.
- Observe that nothing happens, even though the first line has 125 characters and so should be reformatted.
Expected behavior
The code is reformatted and all lines have 88 or fewer characters.
Environment (please complete the following information):
- Version: black-19.10b0
- OS and Python version: Mac OS Mojava 10.14.6 / Python 3.7
Does this bug also happen on master? Yes (checked using website)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Change 88 characters limit for Black plugin in PyCharm
I am using the Black-Pycharm plugin, unfortunately, selecting code and applying Black on it ( Code > Reformat Code (BLACK) ) cuts all...
Read more >The Black code style - Black 22.12.0 documentation
The rest of this document describes the current formatting style. ... Black defaults to 88 characters per line, which happens to be 10%...
Read more >How to Auto-Format Your Python Code with Black
Note that Black defaults to 88 characters for its line length, but you can change that using the “-l” or “- -line-length” option....
Read more >Chapter 3 - Code Formatting with Black
Horizontal spacing has more to it than just the indentation. Spaces are important for making different parts of a code line appear visually...
Read more >How to use black, flake8, and isort to format Python codes
Let's explain each option. -l or --line-length : How many characters per line to allow. [default: 88]; - ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I, too, am seeing lines rendered very long, well beyond PEP8 recommendations.
With line-length = 80 (could be anything reasonable), my PEP8 line renders as
However, with black I have
Do scroll to the right… it’s long. While I’m all for
black
(I just blackified by codebase), this one is pretty wonky.black
’s reluctance to use\
chars is fine, but respecting line lengths (-ish) should strongly contribute to the solver’s figure-of-merit calculation.System details are:
I just confirmed this behavior on your black tip site.
Issues that are related, to greater or lesser degrees, appear to be: #1094, #951, #933, #917, #809, #664 and #510.
Not sure if I should make this a separate issue but I’m also seeing this type of issue with dicts whose strings and values are both very long string literals, and
"key":"value"
is longer than the max line length but"key":\n"value"
would not be – black does not break the line at the colon, even though it should.