Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

How to work with long literal lines in docstring? (backslash-newline not supported) #234

Closed
@glennmatthews

Description

@glennmatthews

If I have have long lines in a docstring that need to remain so (e.g., a doctest that produces long output), it gets flagged by pycodestyle for exceeding the 79-character line limit (E501). However, if I use backslash-newlines to wrap the doctest, then pydocstyle flags it with D207 and D301. Short of using # noqa, is there some other workaround? If not, can D207/D301 be enhanced to permit backslash-newline wrapping as valid?

example.py:

"""Module docstring."""


def foo():
    """Docstring not liked by pycodestyle.

    >>> print("this is a doctest which produces some long unwrapped output, sorry about that!")
    this is a doctest which produces some long unwrapped output, sorry about that!
    """
    pass


def bar():
    """Docstring not liked by pydocstyle.

    >>> print("this is a doctest which produces some long unwrapped output,\
sorry about that!")
    this is a doctest which produces some long unwrapped output,\
sorry about that!
    """
    pass


if __name__ == "__main__":
    import doctest
    doctest.testmod()
GLMATTHE-M-33R4:cot glmatthe$ pycodestyle example.py
example.py:7:80: E501 line too long (95 > 79 characters)
example.py:8:80: E501 line too long (82 > 79 characters)
GLMATTHE-M-33R4:cot glmatthe$ pydocstyle example.py
example.py:13 in public function `bar`:
        D301: Use r""" if any backslashes in a docstring
example.py:13 in public function `bar`:
        D207: Docstring is under-indented

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions