-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
D406 removes colons where D416 adds them #13139
Comments
Ahhh, it took me a little bit of time to reproduce this, because it seems that while it's D416 adding the colon to your first snippet, it's D406 that's removing them from your second snippet! So Anyway, I've now reproduced it! |
So I think the reason for this is that Ruff is inferring the incorrect docstring convention. Not sure yet whether it's inferring I'll keep this open for now though, since I believe we infer the docstring convention in some of our other rules... if so, we should maybe try to do that here as well. (Or maybe we already do? If so, we should do it better, since it's pretty obvious to me that you're using |
Okay, inserting these debug prints confirms that because you haven't explicitly selected a docstring convention in your --- a/crates/ruff_linter/src/docstrings/styles.rs
+++ b/crates/ruff_linter/src/docstrings/styles.rs
@@ -2,7 +2,7 @@ use crate::docstrings::google::GOOGLE_SECTIONS;
use crate::docstrings::numpy::NUMPY_SECTIONS;
use crate::docstrings::sections::SectionKind;
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug)]
pub(crate) enum SectionStyle {
Numpy,
Google,
diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs
index 95e0c46af..9fdb344b1 100644
--- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs
+++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs
@@ -1327,10 +1327,10 @@ pub(crate) fn sections(
section_contexts: &SectionContexts,
convention: Option<Convention>,
) {
- match convention {
+ match dbg!(convention) {
Some(Convention::Google) => parse_google_sections(checker, docstring, section_contexts),
Some(Convention::Numpy) => parse_numpy_sections(checker, docstring, section_contexts),
- Some(Convention::Pep257) | None => match section_contexts.style() {
+ Some(Convention::Pep257) | None => match dbg!(section_contexts.style()) {
SectionStyle::Google => parse_google_sections(checker, docstring, section_contexts),
SectionStyle::Numpy => parse_numpy_sections(checker, docstring, section_contexts), This seems like a clear bug to me. |
Wow well investigated!!! So I can fix the issue by setting the template, but it is also a bug that other user might benefit from having fixed? |
Exactly! I'm working on a fix now. |
"section-name-ends-in-colon", "D416", "removed", "autofix"
Ruff seems to auto-fix
to
, but it changes (in my eyes erroneously?):
to
Should this be the case?
The command you invoked (e.g.,
ruff /path/to/file.py --fix
), ideally including the--isolated
flag.Any ruff command with autofix
The current Ruff settings (any relevant sections from your
pyproject.toml
).ruff --version
).0.6.2
The text was updated successfully, but these errors were encountered: