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

[pydocstyle-D405] Allow using parameters as a sub-section header #9894

Conversation

mikeleppane
Copy link
Contributor

Summary

This review contains a fix for D405 (capitalize-section-name)
The problem is that Ruff considers the sub-section header as a normal section if it has the same name as some section name. For instance, a function/method has an argument named "parameters". This only applies if you use Numpy style docstring.

See: ISSUE

The following will not raise D405 after the fix:

def some_function(parameters: list[str]):
    """A function with a parameters parameter

    Parameters
    ----------

    parameters:
        A list of string parameters
    """
    ...

Test Plan

cargo test

@mikeleppane mikeleppane changed the title [pydocstyle-D405] Allow using *parameters* as a sub-section header [pydocstyle-D405] Allow using parameters as a sub-section header Feb 8, 2024
Copy link
Contributor

github-actions bot commented Feb 8, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh self-requested a review February 8, 2024 17:39
@charliermarsh charliermarsh added bug Something isn't working docstring Related to docstring linting or formatting labels Feb 8, 2024
@charliermarsh charliermarsh force-pushed the fix(D405)/allow_using_section_name_as_sub_section_header branch from ed05447 to 960a60f Compare February 8, 2024 21:12
@mikeleppane
Copy link
Contributor Author

Note: check that the condition still holds if an arg name is different than Parameters but some other section name e.g returns.

@charliermarsh
Copy link
Member

@mikeleppane - Can you post an example?

@mikeleppane
Copy link
Contributor Author

Sorry, I forgot to add a test case for this.

def foo(returns: int):
   """
   Parameters
   -‐-----------------
   returns:
       some value

   """

@charliermarsh
Copy link
Member

Ahh ok yes, the change I made here doesn't cover that case.

@charliermarsh
Copy link
Member

I have an idea for it, thanks.

@charliermarsh charliermarsh merged commit b4f2882 into astral-sh:main Feb 9, 2024
17 checks passed
@charliermarsh
Copy link
Member

Thanks as always @mikeleppane!

nkxxll pushed a commit to nkxxll/ruff that referenced this pull request Mar 10, 2024
…stral-sh#9894)

## Summary

This review contains a fix for
[D405](https://docs.astral.sh/ruff/rules/capitalize-section-name/)
(capitalize-section-name)
The problem is that Ruff considers the sub-section header as a normal
section if it has the same name as some section name. For instance, a
function/method has an argument named "parameters". This only applies if
you use Numpy style docstring.

See: [ISSUE](astral-sh#9806)

The following will not raise D405 after the fix:
```python  
def some_function(parameters: list[str]):
    """A function with a parameters parameter

    Parameters
    ----------

    parameters:
        A list of string parameters
    """
    ...
```


## Test Plan

```bash
cargo test
```

---------

Co-authored-by: Mikko Leppänen <[email protected]>
Co-authored-by: Charlie Marsh <[email protected]>
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.

3 participants