ruff rule E501: Fix long lines in Python code #1910
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
%
ruff rule E501# Requested at #1909 (review)line-too-long (E501)
Derived from the pycodestyle linter.
What it does
Checks for lines that exceed the specified maximum character length.
Why is this bad?
Overlong lines can hurt readability. PEP 8, for example, recommends
limiting lines to 79 characters. By default, this rule enforces a limit
of 88 characters for compatibility with Black and the Ruff formatter,
though that limit is configurable via the [
line-length] setting.In the interest of pragmatism, this rule makes a few exceptions when
determining whether a line is overlong. Namely, it:
whitespace between its characters).
the line-length threshold.
# type: ignoreor
# noqa), as long as the pragma comment starts before theline-length threshold. That is, a line will not be flagged as
overlong if a pragma comment causes it to exceed the line length.
(This behavior aligns with that of the Ruff formatter.)
(e.g.,
# SPDX-License-Identifier: MIT), which are machine-readableand should not wrap over multiple lines.
If [
lint.pycodestyle.ignore-overlong-task-comments] istrue, this rule willalso ignore comments that start with any of the specified [
lint.task-tags](e.g.,
# TODO:).Example
Use instead:
Error suppression
Hint: when suppressing
E501errors within multi-line strings (likedocstrings), the
noqadirective should come at the end of the string(after the closing triple quote), and will apply to the entire string, like
so:
Options
line-lengthlint.task-tagslint.pycodestyle.ignore-overlong-task-commentslint.pycodestyle.max-line-length