Skip to content
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

How to ignore E501: Line too long in docstrings #9200

Closed
DanielNoord opened this issue Dec 19, 2023 · 3 comments · Fixed by #9205
Closed

How to ignore E501: Line too long in docstrings #9200

DanielNoord opened this issue Dec 19, 2023 · 3 comments · Fixed by #9205
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@DanielNoord
Copy link
Contributor

def func():
    """
    My very long docstring that I can't seem to be able to get under 100 characters but that I don't want to change.
    """

    string = "My very long string that I can't seem to be able to get under 100 characters but that should be changed"

Running ruff --select=E501 --line-length=100 test.py.

How can I ignore E501 on the line in the docstring but not in the string line. I have tried to do this but can't figure out how to do so. pylint read the ignore comment even if it is in a docstring, would that be a possibility here?

@charliermarsh
Copy link
Member

The # noqa for multi-line strings need to come at the end of the multi-line string, kinda like this:

def func():
    """
    My very long docstring that I can't seem to be able to get under 100 characters but that I don't want to change.
    """  # noqa: E501

This ensures that the # noqa doesn't appear within the actual string contents.

@DanielNoord
Copy link
Contributor Author

Thanks @charliermarsh, that's what I was looking for.

Not sure if these should be added to the line-too-long docs. Multi-line strings and docstrings are different objects and I couldn't find anything through google/GIthub when looking for docstrings. Adding a short example for them might help with discoverability.

@charliermarsh
Copy link
Member

Good call -- it's mentioned in the docs here but it should probably be mentioned in the rule documentation since this does come up often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants