ruff: Ruff complains about a too long line which black does not format

Ruff complains about this (in file issue.py), although black doesn’t change this code


class A:
    def my_func(self, constants):
        headers = {
            constants.HEADERS.CONTENT_TYPE.value: constants.CONTENT_TYPE.URL_ENCODED.value
        }

The line is ofc constants.HEADERS.CONTENT_TYPE.value: constants.CONTENT_TYPE.URL_ENCODED.value, which has 90 chars

Ruff version: 0.0.275 Invoked command: ruff check issue.py No configuration added to pyproject.toml for either ruff or black (so both should assume a max line-length of 88)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17 (9 by maintainers)

Most upvoted comments

@nbro10 I think this is clearly documented at https://beta.ruff.rs/docs/faq/#is-ruff-compatible-with-black — is there somewhere else you think this information should be highlighted?

Black cannot safely automatically split some long lines. In these cases, it is valuable to many users to have a linter highlight the line length violation so it can be split manually.

Ah yeah, this is by-design and consistent with Flake8 and other linters. In general, the line-length check is just looking at the length of the physical line, and not whether a formatter has the ability to truncate it. If you want to rely on Black to enforce line length, you might consider disabling E501 altogether.