You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
W505: Warning raised for comments in addition to docstrings #15733
W505 (doc line too long) is raised for docstrings that are too long, but it is also raised for comments (and commented-out code). Comments, and commented-out code in particular, are not docs and I feel they should be treated differently.
# example.pyclassFoo:
"""A really long docstring that goes on and on and should be split into multiple lines."""def__init__(self):
pass# print("This is some code that is less than 119 characters and that we commented out.")
$ ruff check
example.py:2:81: W505 Doc line too long (94 > 80)
|
1 | class Foo:
2 |"""A really long docstring that goes on and on and should be split into multiple lines."""| ^^^^^^^^^^^^^^ W505
3 |
4 | def __init__(self):
|
example.py:6:81: W505 Doc line too long (100 > 80)
|
4 | def __init__(self):
5 | pass
6 |# print("This is some code that is less than 119 characters and that we commented out.")| ^^^^^^^^^^^^^^^^ W505
|
@ntBre Thanks for the reply! That's interesting, I'm fairly sure I didn't used to get these warnings for comments in the past before switching to ruff, but maybe I wasn't using pycodestyle. In that case, it looks like this is behaving as intended (i.e. it matches pycodestyle's behavior), and with your suggested workaround I'm sufficiently satisfied that I think I can close this issue.
Activity
ntBre commentedon Jan 24, 2025
It looks like we inherited this behavior from pycodestyle, which also applies it to comments:
https://github.com/PyCQA/pycodestyle/blob/368d9dc21496e4cbb26a00b9e167deed39865781/pycodestyle.py#L1664-L1665
So I'm not sure we'd really want to depart from that.
It's a bit hacky, but as the docs suggest, you can avoid W505 on lines that match one of your lint.task-tags if you combine it with lint.pycodestyle.ignore-overlong-task-comments:
ruff check --select W505 \ --config 'lint.pycodestyle.max-doc-length = 80' \ --config 'lint.pycodestyle.ignore-overlong-task-comments = true' \ --config 'lint.task-tags = [""]' example.pyThe empty
task-tagshould match any comment.This reports the error for the docstring but not for the comment.
martimlobao commentedon Jan 25, 2025
@ntBre Thanks for the reply! That's interesting, I'm fairly sure I didn't used to get these warnings for comments in the past before switching to
ruff, but maybe I wasn't usingpycodestyle. In that case, it looks like this is behaving as intended (i.e. it matchespycodestyle's behavior), and with your suggested workaround I'm sufficiently satisfied that I think I can close this issue.