Skip to content

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

Merged
charliermarsh merged 5 commits into
astral-sh:mainfrom
mikeleppane:fix(D405)/allow_using_section_name_as_sub_section_header
Feb 9, 2024
Merged

[pydocstyle-D405] Allow using parameters as a sub-section header#9894
charliermarsh merged 5 commits into
astral-sh:mainfrom
mikeleppane:fix(D405)/allow_using_section_name_as_sub_section_header

Conversation

@mikeleppane
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@mikeleppane - Can you post an example?

@mikeleppane
Copy link
Copy Markdown
Contributor Author

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

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

   """

@charliermarsh
Copy link
Copy Markdown
Member

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

@charliermarsh
Copy link
Copy Markdown
Member

I have an idea for it, thanks.

@charliermarsh charliermarsh merged commit b4f2882 into astral-sh:main Feb 9, 2024
@charliermarsh
Copy link
Copy Markdown
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 <mikko.leppanen@vaisala.com>
Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
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