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

Errors in multiline docstrings point to the first line of the string #10736

Closed
ts933 opened this issue Apr 2, 2024 · 5 comments · Fixed by #10740
Closed

Errors in multiline docstrings point to the first line of the string #10736

ts933 opened this issue Apr 2, 2024 · 5 comments · Fixed by #10740
Assignees
Labels
docstring Related to docstring linting or formatting

Comments

@ts933
Copy link

ts933 commented Apr 2, 2024

ruff version==0.2.1

pyproject.toml


[tool.ruff]
preview = true

select = [
  "C90", # McCabe
  "D",   # pydocstyle
  "E",   # pycodestyle
  "F",   # pyflakes
  "NPY", # numpy specific
  "PL",  # pylint
  "PTH", # flake8-use-pathlib
  "SIM", # flake8-simplify
  "TD",  # flake8-todos
  "UP",  # pyupgrade
  "W",   # pycodestyle
]
line-length = 120

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.mccabe]
max-complexity = 5


@MichaReiser
Copy link
Member

@ts933 would you mind providing a minimal code example that demonstrates the problem? It would help us to understand what you're asking for or consider a bug. Thank you

@MichaReiser MichaReiser added the needs-info More information is needed from the issue author label Apr 2, 2024
@ts933
Copy link
Author

ts933 commented Apr 2, 2024

Code with 4 errors all pointing to the same line --> 10

`def extract_category(dataframe,  # type: ignore   # pragma: no cover
                     keyword,
                     filter_on_column='category',
                     label='io') -> pd.DataFrame:
    """Extracts rows from a given dataframe based on a filter condition and assigns a label of 0 or 1 to each row.

    Args:

        dataframe (pyspark.sql.DataFrame): The input dataframe.
        keyword (str): The keyword to match in the filter column.
        filter_on_column (str, optional): The column to filter on.
        label (str): If we want to label the data as IO or NIO.
    Returns:

        pd.DataFrame: The extracted rows with an additional 'label' column assigned with a value of 1.
    """`

file.py:10:5: D410 [] Missing blank line after section ("Args")
file.py:10:5: D412 [
] No blank lines allowed between a section header and its content ("Args")
file.py:10:5: D411 [] Missing blank line before section ("Returns")
file.py:10:5: D412 [
] No blank lines allowed between a section header and its content ("Returns")

@MichaReiser
Copy link
Member

I would need to look into what the reason for this is. @charliermarsh any chance it is so that the noqa comments work for multiline docstrings (because they match on the start of the line?)

@charliermarsh
Copy link
Member

No, that shouldn’t be necessary for the noqa enforcement. I can take a look at this. My guess is we highlight the whole docstring, and so the start character is indeed the first line? Not sure though, I’ll look later.

@charliermarsh charliermarsh self-assigned this Apr 2, 2024
@charliermarsh
Copy link
Member

Yeah, these rules just use the range of the docstring. We could consider refining them.

@charliermarsh charliermarsh added docstring Related to docstring linting or formatting and removed needs-info More information is needed from the issue author labels Apr 2, 2024
charliermarsh added a commit that referenced this issue Apr 3, 2024
…10740)

## Summary

We may not have had access to this in the past, but in short, if the
diagnostic is related to a specific section of a docstring, it seems
better to highlight the section (via the header) than the _entire_
docstring.

This should be completely compatible with existing `# noqa` since it's
always inside of a multi-line string anyway, and in such cases the `#
noqa` is always placed at the end of the multiline string.

Closes #10736.
Glyphack pushed a commit to Glyphack/ruff that referenced this issue Apr 12, 2024
…stral-sh#10740)

## Summary

We may not have had access to this in the past, but in short, if the
diagnostic is related to a specific section of a docstring, it seems
better to highlight the section (via the header) than the _entire_
docstring.

This should be completely compatible with existing `# noqa` since it's
always inside of a multi-line string anyway, and in such cases the `#
noqa` is always placed at the end of the multiline string.

Closes astral-sh#10736.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants