Skip to content

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

@aureliojargas

Description

@aureliojargas

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

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions