Skip to content

Commit

Permalink
b024 no longer treats assigned class vars as abstract (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl authored Oct 28, 2024
1 parent ba3a9bf commit cf8749c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

os: [ubuntu-latest]

Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ MIT
Change Log
----------


FUTURE
~~~~~~
* B024: No longer treats assigned class variables as abstract (#471)

24.8.19
~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ def is_str_or_ellipsis(node):
for stmt in node.body:
# 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)):
if isinstance(stmt, ast.AnnAssign) and stmt.value is None:
has_abstract_method = True
continue

Expand Down
18 changes: 13 additions & 5 deletions tests/b024.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"""
Should emit:
B024 - on lines 17, 34, 52, 58, 69, 74, 84, 89
B024 - on lines 17, 52, 58, 69, 74, 123, 129
"""


Expand All @@ -31,7 +31,7 @@ def method(self):
foo()


class Base_4(ABC):
class Base_4(ABC): # safe
@notabc.abstractmethod
def method(self):
foo()
Expand Down Expand Up @@ -112,16 +112,24 @@ def method(self):
foo()


class abc_set_class_variable_1(ABC): # safe
# safe, see https://github.com/PyCQA/flake8-bugbear/issues/293
class abc_annasign_empty_class_variable_1(ABC):
foo: int
def method(self):
foo()


class abc_set_class_variable_2(ABC): # safe
# *not* safe, see https://github.com/PyCQA/flake8-bugbear/issues/471
class abc_assign_class_variable(ABC):
foo = 2
def method(self):
foo()


class abc_set_class_variable_3(ABC): # safe
class abc_annassign_class_variable(ABC): # *not* safe, see #471
foo: int = 2
def method(self):
foo()


# this doesn't actually declare a class variable, it's just an expression
Expand Down
2 changes: 2 additions & 0 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ def test_b024(self):
B024(58, 0, vars=("MetaBase_1",)),
B024(69, 0, vars=("abc_Base_1",)),
B024(74, 0, vars=("abc_Base_2",)),
B024(123, 0, vars=("abc_assign_class_variable",)),
B024(129, 0, vars=("abc_annassign_class_variable",)),
)
self.assertEqual(errors, expected)

Expand Down

0 comments on commit cf8749c

Please sign in to comment.