Skip to content

Comments

Disambiguate argument descriptors from section headers#9427

Merged
charliermarsh merged 1 commit intomainfrom
charlie/nested-args
Jan 8, 2024
Merged

Disambiguate argument descriptors from section headers#9427
charliermarsh merged 1 commit intomainfrom
charlie/nested-args

Conversation

@charliermarsh
Copy link
Member

Summary

Given a docstring like:

def func(x: int, args: tuple[int]):
    """Toggle the gizmo.

    Args:
        x: Some argument.
        args: Some other arguments.
    """

We were considering the args: descriptor to be an indented docstring section header (since Args:) is a valid header name. This led to very confusing diagnostics.

This PR makes the parsing a bit more lax in this case, such that if we see a nested header that's more deeply indented than the preceding header, and the preceding section allows sub-items (like Args:), we avoid treating the nested item as a section header.

Closes #9426.

@charliermarsh charliermarsh added bug Something isn't working docstring Related to docstring linting or formatting labels Jan 8, 2024
@charliermarsh charliermarsh marked this pull request as ready for review January 8, 2024 02:35
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh merged commit 04afdf1 into main Jan 8, 2024
@charliermarsh charliermarsh deleted the charlie/nested-args branch January 8, 2024 03:41
ntBre added a commit that referenced this pull request Feb 11, 2025
…7`) (#16011)

## Summary

Fixes #16007. The logic from the last fix for this (#9427) was
sufficient, it just wasn't being applied because `Attributes` sections
aren't expected to have nested sections. I just deleted the outer
conditional, which should hopefully fix this for all section types.

## Test Plan

New regression test, plus the existing D417 tests.
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

Successfully merging this pull request may close these issues.

Variable named "args" leads to ambiguous docstring parsing

1 participant