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

B024 false negative when there's a class var #11208

Closed
aureliojargas opened this issue Apr 29, 2024 · 1 comment · Fixed by #11210
Closed

B024 false negative when there's a class var #11208

aureliojargas opened this issue Apr 29, 2024 · 1 comment · Fixed by #11210
Assignees
Labels
rule Implementing or modifying a lint rule

Comments

@aureliojargas
Copy link
Contributor

Taking the example from https://docs.astral.sh/ruff/rules/abstract-base-class-without-abstract-method/

from abc import ABC


class Foo(ABC):
    def method(self):
        bar()

B024 detects it as expected:

$ ruff --version
ruff 0.4.2
$ ruff check --isolated --select B024 abc.py 
abc.py:4:7: B024 `Foo` is an abstract base class, but it has no abstract methods
Found 1 error.
$

But if I add a simple class var, now it passes:

from abc import ABC


class Foo(ABC):
    BAR = 1

    def method(self):
        bar()
$ ruff check --isolated --select B024 abc.py
All checks passed!

Is that expected?

Playground: https://play.ruff.rs/f0b51911-407f-4bd7-af7c-c9f5b1116677

@charliermarsh
Copy link
Member

It looks like it's due to PyCQA/flake8-bugbear#293, but I think we can refine this check.

@charliermarsh charliermarsh self-assigned this Apr 30, 2024
@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Apr 30, 2024
charliermarsh added a commit that referenced this issue Apr 30, 2024
## Summary

I think the check included here does make sense, but I don't see why we
would allow it if a value is provided for the attribute -- since, in
that case, isn't it _not_ abstract?

Closes: #11208.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants