Skip to content

DOC502: False positive if following text contains a colon #18959

@dargueta

Description

@dargueta

Summary

Possibly related to #16578 but somewhat different: Text after the Raises block triggers a false positive for DOC502 if that text contains a colon.

In my case, the relevant part of the docstring contains Sphinx directives, properly unindented:

Raises:
    ExtraneousDataError:
        ``exact`` is True and there's data left over at the end of the byte
        string.

.. versionadded:: 0.7.0
    The ``init_kwargs`` argument.

This results in a false positive:

Raised exception is not explicitly raised: `. versionadded` (DOC502) [Ln 7, Col 5]

Note the line number is also wrong; it's line 27 of the docstring, line 6 of the Raises section if you include the line with "Raises" on it.

It seems like Ruff thinks versionadded: is part of the Raises block, even though it's unindented. Interestingly, removing both colons from versionadded makes the issue go away. Adding just one back triggers the bug again.

Playground link: https://play.ruff.rs/2f264f7b-d661-4af3-83e0-2db04e30ced8

Version

0.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocstringRelated to docstring linting or formatting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions