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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

D403 does not trigger for a single-word docstring that ends with a period #10775

Closed
jbmoorhouse opened this issue Apr 4, 2024 · 3 comments 路 Fixed by #10776
Closed

D403 does not trigger for a single-word docstring that ends with a period #10775

jbmoorhouse opened this issue Apr 4, 2024 · 3 comments 路 Fixed by #10776
Labels
bug Something isn't working docstring Related to docstring linting or formatting

Comments

@jbmoorhouse
Copy link

Keywords searched for

D403 -> Potentially related to #2989

Ruff version

0.3.0

Issue

For a docstring with one word (admittedly not a typical docstring 馃槈), if the word is not capitalised and there is no fullstop, the correct errors are raised

image

However, when adding a full stop, D403 is suppressed/not raised

image

@AlexWaygood AlexWaygood added the docstring Related to docstring linting or formatting label Apr 4, 2024
@MichaReiser
Copy link
Member

MichaReiser commented Apr 4, 2024

I think this is probably a bug in the check here

let Some(first_word) = body.split(' ').next() else {
return;
};

It splits by whitespace to get the first word. But that means it returns early if it's a single word. We should probably change this to

let first_word = body.split(' ').next().unwrap_or(&body);

@AlexWaygood AlexWaygood changed the title D403 issue D403 does not trigger for a single-word docstring that ends with a period Apr 4, 2024
@AlexWaygood AlexWaygood added the bug Something isn't working label Apr 4, 2024
@MichaReiser
Copy link
Member

Okay, that's not sufficient, because it then gets skipped in

    for char in first_word.chars() {
        if !char.is_ascii_alphabetic() && char != '\'' {
            dbg!("Non ascii character");
            return;
        }
    }

I need to look into the pycodestyle implementation if this is intentional.

@MichaReiser
Copy link
Member

Okay, I was wrong. Split is used correctly. It always returns the string even if the split character isn't found. It bails because . isn't an ASCII character, and this matches pydocstyle's implementation.

I'll put up a PR but I"m not sure if we should change the current behavior because a single word isn't really a phrase...

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 a pull request may close this issue.

3 participants