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

False negative with useless-expression on strings #11292

Open
NeilGirdhar opened this issue May 5, 2024 · 4 comments · May be fixed by #11302
Open

False negative with useless-expression on strings #11292

NeilGirdhar opened this issue May 5, 2024 · 4 comments · May be fixed by #11302
Labels
bug Something isn't working

Comments

@NeilGirdhar
Copy link

NeilGirdhar commented May 5, 2024

For some reason useless-expression is not triggered by loose strings. Should these be caught? If comments are intended, then Ruff could suggest converting them comments?

class X:
    """Some docstring."""


def f() -> None:
    """Some docstring."""
    [123]  # noqa: B018
    "Some loose string."  # Should be B018.


x = 1
"""Some editors consider this a variable docstring, but it doesn't affect any __doc__ and
ordinary comments are ubiquitous."""
@charliermarsh
Copy link
Member

The intention here is to avoid flagging docstrings, but I think we need to make it more targeted.

@charliermarsh charliermarsh added the bug Something isn't working label May 5, 2024
@NeilGirdhar
Copy link
Author

NeilGirdhar commented May 5, 2024

Yeah, that's what I figured. I tried to illustrate some reasonable uses of strings. I'm not sure how you feel about the "variable docstring", which some editors recognize. As far as I know, they're rarely used and not really a Python concept. They look pretty weird in code:

length: int  # The length of the object.
width: int  # The width of the object.

versus

length: int
"The length of the object."
width: int
"The width of the object."

@charliermarsh
Copy link
Member

Yeah, I think we do need to ignore attribute docstrings. They're not standardized, but they're popular enough that I think it'd be a net-negative to flag them.

@dhruvmanila
Copy link
Member

I think this can be fixed because our docstring detection is quite accurate now.

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.

3 participants