Skip to content

Ignore D412 (blank-lines-between-header-and-content) if a reStructuredText directive follows a section header #11577

@harupy

Description

@harupy

Originally found in pytest-dev/pytest#12375 where I was trying to fix pytest's API reference. The following code violates D412, but sphinx doesn't render the docstring correctly if the blank line after Example: is removed.

# violates D412

def f():
    """
    Example:

    .. code-block:: python

        import foo
    """

Autofixed code:

# doesn't violate D412, but sphinx fails to render correctly

def f():
    """
    Example:
    .. code-block:: python

        import foo
    """

image

Repro on playground: https://play.ruff.rs/b4c94827-8503-4568-978d-59e74a31a01b

Metadata

Metadata

Assignees

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