Skip to content

Commit 65c141e

Browse files
committed
fix B024 & B027 on python < 3.8
1 parent 8462c1f commit 65c141e

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

README.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,23 +296,21 @@ MIT
296296

297297
Change Log
298298
----------
299+
Future
300+
~~~~~~~~~
301+
302+
* Add B027: Empty method in abstract base class with no abstract decorator
299303

300-
<<<<<<< HEAD
301304
22.9.23
302305
~~~~~~~~~~
303306

304-
* add B026: find argument unpacking after keyword argument (#287)
307+
* Add B026: find argument unpacking after keyword argument (#287)
305308
* Move to setup.cfg like flake8 (#288)
306309

307310
22.9.11
308311
~~~~~~~~~~
309312

310-
* add B025: find duplicate except clauses (#284)
311-
=======
312-
Future
313-
~~~~~~~~~
314-
* Add B025: Empty method in abstract base class with no abstract decorator.
315-
>>>>>>> 0937a2d (Adding B025: empty method in abstract base class with no abstract decorator)
313+
* Add B025: find duplicate except clauses (#284)
316314

317315
22.8.23
318316
~~~~~~~~~~

bugbear.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,17 @@ def is_abstract_decorator(expr):
635635
)
636636

637637
def empty_body(body) -> bool:
638+
def is_str_or_ellipsis(node):
639+
# ast.Ellipsis and ast.Str used in python<3.8
640+
return isinstance(node, (ast.Ellipsis, ast.Str)) or (
641+
isinstance(node, ast.Constant)
642+
and (node.value is Ellipsis or isinstance(node.value, str))
643+
)
644+
638645
# Function body consist solely of `pass`, `...`, and/or (doc)string literals
639646
return all(
640647
isinstance(stmt, ast.Pass)
641-
or (
642-
isinstance(stmt, ast.Expr)
643-
and isinstance(stmt.value, ast.Constant)
644-
and (
645-
stmt.value.value is Ellipsis
646-
or isinstance(stmt.value.value, str)
647-
)
648-
)
648+
or (isinstance(stmt, ast.Expr) and is_str_or_ellipsis(stmt.value))
649649
for stmt in body
650650
)
651651

tests/test_bugbear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def test_b027(self):
407407
B027(16, 4, vars=("empty_2",)),
408408
B027(19, 4, vars=("empty_3",)),
409409
B027(23, 4, vars=("empty_4",)),
410-
B027(31, 4, vars=("empty_5",)),
410+
B027(31 if sys.version_info >= (3, 8) else 30, 4, vars=("empty_5",)),
411411
)
412412
self.assertEqual(errors, expected)
413413

0 commit comments

Comments
 (0)