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 #471

Open
aureliojargas opened this issue Apr 30, 2024 · 0 comments
Open

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

aureliojargas opened this issue Apr 30, 2024 · 0 comments

Comments

@aureliojargas
Copy link

from abc import ABC


class Foo(ABC):
    BAR = 1

    def method(self):
        bar()

Because of the BAR = 1 declaration, B024 is considering Foo an ABC, but it isn't.

Expected:

$ flake8 --isolated --select B024 abc.py
abc.py:4:1: B024 Foo is an abstract base class, but none of the methods it defines are abstract. This is not necessarily an error, but you might have forgotten to add the @abstractmethod decorator, potentially in conjunction with @classmethod, @property and/or @staticmethod.
$

But got:

$ flake8 --isolated --select B024 abc.py
$

Info:

$ flake8 --version
7.0.0 (flake8-bugbear: 24.4.26, mccabe: 0.7.0, pycodestyle: 2.11.1, pyflakes: 3.2.0) CPython 3.12.2 on Darwin

This looks related to the fix for #293.

If I comment out this code, it works as expected:

flake8-bugbear/bugbear.py

Lines 925 to 929 in d1aec4c

# https://github.com/PyCQA/flake8-bugbear/issues/293
# Ignore abc's that declares a class attribute that must be set
if isinstance(stmt, (ast.AnnAssign, ast.Assign)):
has_abstract_method = True
continue

By the way, this same issue was reported to ruff in astral-sh/ruff#11208 and they got a fix. Maybe here a similar patch would work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant