-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter: wrap comments (E501
)
#7414
Comments
Hey @kdeldycke — I think there are some fair concerns raised in the Black issue but thanks for starting the discussion! Out of curiosity, would docstring formatting resolve most of your needs here? |
In the mean time,
def test():
# This is a very very very very very very very very very very very very
# very very very very very long comment.
pass
|
Oh yes. I'm just starting to understand the complexity of the issue. It's hard to generalize comment autoformat. Especially because of the line-dependency of
Oh you mean moving this long comment into a docstring? On paper yes. And yes, I guess when comments become that long, it is time to consider moving them into your function's docstring. I still have the case in which I need long comments: to not have them appears in the auto-generated Sphinx documentation. I have some places in my code where I need long explanation of implementation details, but don't want to distract the user of my library with these implementation details in the top-level documentation. |
I've just come across this again and wanted to throw in something for consideration if this gets implemented... Some directives in Sphinx, e.g. #: A generic type variable.
T = TypeVar("T") It would be nice to preserve the correct comment marker when wrapping, i.e. the following: #: This is a very very very very very very very very very very very very very very very very very long comment.
MAGIC_NUMBER = 123 ...after formatting would produce: #: This is a very very very very very very very very very very very very very very very
#: very very long comment.
MAGIC_NUMBER = 123 ...and not this: #: This is a very very very very very very very very very very very very very very very
# very very long comment.
MAGIC_NUMBER = 123 Another thing for consideration might be what happens with comment tags, as defined in Like this? # TODO: This is a very very very very very very very very very very very very very very
# very very very long comment. Or like this? (Which I personally like...) # TODO: This is a very very very very very very very very very very very very very very
# very very very long comment. |
Playing with the beta formatter, I was curious why it did not wrap long comments.
See the following
long.py
file:Running the latest
ruff
version, the file is left unchanged, while I expected the long comment line to be wrapped:I then realized that Black itself doesn't format comments. Even in its last iteration:
Wrapping comments would be a nice quality of life improvement to auto-fix a number of
E501
rule violations.The text was updated successfully, but these errors were encountered: