Skip to content

Commit

Permalink
fix B024 & B027 on python < 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Oct 2, 2022
1 parent 8462c1f commit 65c141e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
14 changes: 6 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,23 +296,21 @@ MIT

Change Log
----------
Future
~~~~~~~~~

* Add B027: Empty method in abstract base class with no abstract decorator

<<<<<<< HEAD
22.9.23
~~~~~~~~~~

* add B026: find argument unpacking after keyword argument (#287)
* Add B026: find argument unpacking after keyword argument (#287)
* Move to setup.cfg like flake8 (#288)

22.9.11
~~~~~~~~~~

* add B025: find duplicate except clauses (#284)
=======
Future
~~~~~~~~~
* Add B025: Empty method in abstract base class with no abstract decorator.
>>>>>>> 0937a2d (Adding B025: empty method in abstract base class with no abstract decorator)
* Add B025: find duplicate except clauses (#284)

22.8.23
~~~~~~~~~~
Expand Down
16 changes: 8 additions & 8 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,17 +635,17 @@ def is_abstract_decorator(expr):
)

def empty_body(body) -> bool:
def is_str_or_ellipsis(node):
# ast.Ellipsis and ast.Str used in python<3.8
return isinstance(node, (ast.Ellipsis, ast.Str)) or (
isinstance(node, ast.Constant)
and (node.value is Ellipsis or isinstance(node.value, str))
)

# Function body consist solely of `pass`, `...`, and/or (doc)string literals
return all(
isinstance(stmt, ast.Pass)
or (
isinstance(stmt, ast.Expr)
and isinstance(stmt.value, ast.Constant)
and (
stmt.value.value is Ellipsis
or isinstance(stmt.value.value, str)
)
)
or (isinstance(stmt, ast.Expr) and is_str_or_ellipsis(stmt.value))
for stmt in body
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def test_b027(self):
B027(16, 4, vars=("empty_2",)),
B027(19, 4, vars=("empty_3",)),
B027(23, 4, vars=("empty_4",)),
B027(31, 4, vars=("empty_5",)),
B027(31 if sys.version_info >= (3, 8) else 30, 4, vars=("empty_5",)),
)
self.assertEqual(errors, expected)

Expand Down

0 comments on commit 65c141e

Please sign in to comment.