-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow explicit select of docstring rule to override configured convention #2606
Comments
I think this was overly aggressive. We can reconsider. It was done to avoid things like users accidentally enabling both |
It probably makes sense to treat |
Aye, that sounds like how I expected it to work |
Came here to say that I added |
The current behavior is that it turns off any rules that are incompatible with the convention. So, specifically, So for Dagster, you can remove that first block of [tool.ruff]
select = ["D"]
ignore = [
# (missing public docstrings) These work off of the Python sense of "public", rather than our
# bespoke definition based off of `@public`. When ruff supports custom plugins then we can write
# appropriate rules to require docstrings for `@public`.
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D106",
"D107",
##### TEMPORARY DISABLES
# (assorted docstring rules) There are too many violations of these to enable
# right now, but we should enable after fixing the violations.
"D200", # (one-line docstring should fit)
"D205", # (blank line after summary)
"D212", # (multi-line docstring summary should start at 1st line)
"D415", # (docstring summary should end with a period)
"D417", # (missing arg in docstring)
# (indent docstring rules) These rules should be enabled when ruff lands
# on/off style comments, which would allow turning them off for specific
# docstrings.
"D207", # (under-indented docstring)
"D208", # (over-indented docstring)
"D402", # (first line should not be the function's "signature")
]
[tool.ruff.pydocstyle]
convention = "google" |
The situation seem to be worse for those deciding to use
Does anyone know a way to keep using ALL and avoid these confusing warnings? |
@ssbarnea - Do you mind sharing your configuration? For me, I don't see any warnings with this [tool.ruff]
select = ["ALL"]
[tool.ruff.pydocstyle]
convention = "pep257" |
@charliermarsh Sure, look at https://github.com/ansible/ansible-compat/blob/main/pyproject.toml#L138 -- apparently I get this warning with current ruff too:
|
@ssbarnea - Thanks, I'll take a look now. |
I'm not seeing those warnings, need to think on why they could be showing up for you:
|
Could you share the output of |
Something is confusing ruff, and apparently is not the cache:
Result of settings dump https://gist.github.com/ssbarnea/18819983d585ad1ed674e1a2e2b49616 |
Is there any way you have something like a (Do you not see the warnings when you run |
You are right, I see the warning without even doing anything:
I do not have any other ruff config file in my filesystem other than the git-tracked one at https://github.com/ansible/ansible-lint/blob/main/pyproject.toml#L225-L262 |
just wanna add my +1 to this request. Specifically, I'd love to be able to simply add D417 to numpy docstrings. [tool.ruff]
extend-select = ["D417"]
[tool.ruff.pydocstyle]
convention = "numpy" Currently, I do this by manually including the full numpy include/exclude spec just so I can keep D417. |
Revisiting to say that IMO the current docs are still too uninformative-- if I read https://beta.ruff.rs/docs/settings/#pydocstyle-convention it is not obvious what this does in terms of If the content from #2606 (comment) were posted in the docs that would go a ways. |
For now, I expanded on the documentation in #5819. |
I've been taking a look at this and quite surprised by the behavior. From a code POV, I think the fix should be simple: changing ruff/crates/ruff_workspace/src/configuration.rs Lines 891 to 893 in 4760af3
to something more like: for rule in convention.rules_to_be_ignored() {
if !rules.enabled(*rule) {
rules.disable(*rule);
}
} which would turn the rules off-by-default but allow users to force override it. My question is whether that would be the right path forward, or if we want something more complicated (e.g. if there are rules that are truly incompatible with a convention, then we can distinguish (I also have, uestions aboutf where these rules for the conventions came from -- I would've expected several of them to have been on by default for the numpy convention at least, but I'm happy to move that out of this issue's discussion). |
@alanhdu -- Thanks for taking a look! I think the fix isn't quite that simple. We probably need some logic like: if the rule wasn't explicitly selected (like |
Yeah, I agree this is a little trickier than I first thought. I filed #8586 with what I think is a reasonable approach -- would be happy to discuss more about the implementation there! |
Nice, thanks @alanhdu! Will take a look at that PR later today or tomorrow. |
## Summary This fixes #2606 by moving where we apply the convention ignores -- instead of applying that at the very end, e track, we now track which rules have been specifically enabled (via `Specificity::Rule`). If they have, then we do *not* apply the docstring overrides at the end. ## Test Plan Added unit tests to `ruff_workspace` and an integration test to `ruff_cli`
hooray!! Thanks @alanhdu! |
For anyone else wanting to add D417 while using numpy convention you have to explicitly include it as [tool.ruff.lint]
extend-select = ["D", <other selections>, "D417"]
[tool.ruff.lint.pydocstyle]
convention = "numpy" |
I know this is documented...
...but it seems a little excessive in some cases.
In particular,
convention = "pep257"
disablesD212
andD213
. PEP 257 states:But I'd like to be a little stricter. I'd like to have
convention = "pep257"
and force enableD213
. Not sure whether this is best as a new configuration option to make it something you have to explicitly opt in to, e.g.force-enable = ["D213"]
?(Using v0.0.241.)
The text was updated successfully, but these errors were encountered: