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

PYI010: replace func stub's docstrings with '...' even if there already is one. #7021

Closed
Prometheos2 opened this issue Aug 31, 2023 · 3 comments · Fixed by #7024
Closed

PYI010: replace func stub's docstrings with '...' even if there already is one. #7021

Prometheos2 opened this issue Aug 31, 2023 · 3 comments · Fixed by #7024
Assignees
Labels
bug Something isn't working

Comments

@Prometheos2
Copy link

Prometheos2 commented Aug 31, 2023

Hello,

I've noticed PYI010's autofix replaces function stubs' docstrings with ellipsis regardless of if there is one already or not.

Minimal code snippet

def function():
    """doc"""
    ...

Details

  • The commands I invoked:

    • the VSC extension's autofix
    • ruff . --fix
    • ruff . --fix --isolated --select "PYI" (got a error: Failed to converge after 100 iterations. with this one; will create a new issue soon)
  • The current Ruff version: 0.0.286

The current Ruff settings

  • A ruff.toml file on the project root (linted file is in a typings subfolder)
select = [
	# ...
	"PYI",  # flake8-pyi
	# ...
]
include = ["*.py", "*.pyi", "*.ipynb", "pyproject.toml", "rust.toml"]
ignore = ["E501", "N999"]
target-version = "py38"
src = ["Phonebook_analyzer"]
  • Added a # "PYI010" in unfixable after the first command; no sure if it's relevant.

Thanks for the linter, btw; it's really awesome!

@charliermarsh charliermarsh added the bug Something isn't working label Aug 31, 2023
@charliermarsh charliermarsh self-assigned this Aug 31, 2023
@charliermarsh
Copy link
Member

Thanks for reporting :)

@Prometheos2
Copy link
Author

You're welcome ^^

Do you want me to report the infinite loop? I think it might be due to PYI010 replacing the second ellipsis with an ellipsis

@charliermarsh
Copy link
Member

No thanks, this issue is sufficient. I need to look into the relationship between a few related rules here. (We also may need to remove the autofix here, it seems like it's going to be wrong most of the time.)

charliermarsh added a commit that referenced this issue Aug 31, 2023
## Summary

This PR modifies a few of our rules related to which statements (and how
many) are allowed in function bodies within `.pyi` files, to improve
compatibility with flake8-pyi and improve the interplay dynamics between
them. Each change fixes a deviation from flake8-pyi:

- We now always trigger the multi-statement rule (PYI048) regardless of
whether one of the statements is a docstring.
- We no longer trigger the `...` rule (PYI010) if the single statement
is a docstring or a `pass` (since those are covered by other rules).
- We no longer trigger the `...` rule (PYI010) if the function body
contains multiple statements (since that's covered by PYI048).

Closes #7021.

## Test Plan

`cargo test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants