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

Disambiguate argument descriptors from section headers #9427

Merged
merged 1 commit into from
Jan 8, 2024

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
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
17 checks passed
@charliermarsh charliermarsh deleted the charlie/nested-args branch January 8, 2024 03:41
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