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

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

Closed
harupy opened this issue May 28, 2024 · 3 comments
Assignees
Labels
bug Something isn't working docstring Related to docstring linting or formatting

Comments

@harupy
Copy link
Contributor

harupy commented May 28, 2024

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

@charliermarsh charliermarsh added bug Something isn't working docstring Related to docstring linting or formatting labels May 28, 2024
@charliermarsh
Copy link
Member

We could disable D412 enforcement when followed by a Sphinx code block?

@harupy
Copy link
Contributor Author

harupy commented May 29, 2024

@charliermarsh Thanks for the comment! I think any directive can cause the same issue. For example:

def f():
    """
    Example:
    .. note::

        This example only works on windows.

    .. code-block:: python

        import foo
    """

update: tested this:

image

@charliermarsh charliermarsh self-assigned this May 30, 2024
charliermarsh added a commit that referenced this issue May 30, 2024
)

Given:

```python
def func():
    """
    Example:

    .. code-block:: python

        import foo
    """
```

Removing the newline after the `Example:` header breaks Sphinx
rendering.

See: #11577
@dhruvmanila
Copy link
Member

I think this is resolved by #11609, @charliermarsh feel free to re-open if it's not complete.

bluetech added a commit to bluetech/pytest that referenced this issue Jun 11, 2024
Caused by 4588653.

The issue was fixed in astral-sh/ruff#11577,
so won't trigger again.

Fix pytest-dev#12437.
nicoddemus pushed a commit to pytest-dev/pytest that referenced this issue Jun 11, 2024
Caused by 4588653.

The issue was fixed in astral-sh/ruff#11577,
so won't trigger again.

Fix #12437.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docstring Related to docstring linting or formatting
Projects
None yet
Development

No branches or pull requests

3 participants