question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black incorrectly formatting code - output has lines with more than 88 characters

See original GitHub issue

Describe 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

  1. 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
)
  1. Run Black on it with no arguments.
  2. 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
jaydamaskcommented, Dec 8, 2019

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

    inline_slope_time_series = impulse_response_builder_tools. \
        compute_noncausal_symmetric_first_difference(
            reference_time_series
    )

However, with black I have

    inline_slope_time_series = impulse_response_builder_tools.compute_noncausal_symmetric_first_difference(
        reference_time_series
    )

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:

  • Python 3.7.5
  • black, version 19.3b0
  • Mac OS 10.15.1 (19B88)

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.

4reactions
rben01commented, Feb 22, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found