Skip to content

Commit cf8749c

Browse files
authored
b024 no longer treats assigned class vars as abstract (#494)
1 parent ba3a9bf commit cf8749c

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
12+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
1313

1414
os: [ubuntu-latest]
1515

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ MIT
357357
Change Log
358358
----------
359359

360+
361+
FUTURE
362+
~~~~~~
363+
* B024: No longer treats assigned class variables as abstract (#471)
364+
360365
24.8.19
361366
~~~~~~~
362367

bugbear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def is_str_or_ellipsis(node):
996996
for stmt in node.body:
997997
# https://github.com/PyCQA/flake8-bugbear/issues/293
998998
# Ignore abc's that declares a class attribute that must be set
999-
if isinstance(stmt, (ast.AnnAssign, ast.Assign)):
999+
if isinstance(stmt, ast.AnnAssign) and stmt.value is None:
10001000
has_abstract_method = True
10011001
continue
10021002

tests/b024.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
"""
1212
Should emit:
13-
B024 - on lines 17, 34, 52, 58, 69, 74, 84, 89
13+
B024 - on lines 17, 52, 58, 69, 74, 123, 129
1414
"""
1515

1616

@@ -31,7 +31,7 @@ def method(self):
3131
foo()
3232

3333

34-
class Base_4(ABC):
34+
class Base_4(ABC): # safe
3535
@notabc.abstractmethod
3636
def method(self):
3737
foo()
@@ -112,16 +112,24 @@ def method(self):
112112
foo()
113113

114114

115-
class abc_set_class_variable_1(ABC): # safe
115+
# safe, see https://github.com/PyCQA/flake8-bugbear/issues/293
116+
class abc_annasign_empty_class_variable_1(ABC):
116117
foo: int
118+
def method(self):
119+
foo()
117120

118121

119-
class abc_set_class_variable_2(ABC): # safe
122+
# *not* safe, see https://github.com/PyCQA/flake8-bugbear/issues/471
123+
class abc_assign_class_variable(ABC):
120124
foo = 2
125+
def method(self):
126+
foo()
121127

122128

123-
class abc_set_class_variable_3(ABC): # safe
129+
class abc_annassign_class_variable(ABC): # *not* safe, see #471
124130
foo: int = 2
131+
def method(self):
132+
foo()
125133

126134

127135
# this doesn't actually declare a class variable, it's just an expression

tests/test_bugbear.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ def test_b024(self):
461461
B024(58, 0, vars=("MetaBase_1",)),
462462
B024(69, 0, vars=("abc_Base_1",)),
463463
B024(74, 0, vars=("abc_Base_2",)),
464+
B024(123, 0, vars=("abc_assign_class_variable",)),
465+
B024(129, 0, vars=("abc_annassign_class_variable",)),
464466
)
465467
self.assertEqual(errors, expected)
466468

0 commit comments

Comments
 (0)