From b01e327cfe53ac66f6ea56872d99d7fae607e870 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Thu, 29 Sep 2022 11:48:05 +0200
Subject: [PATCH] fix B024 & B027 on python < 3.8
---
bugbear.py | 11 ++++++++---
tests/test_bugbear.py | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/bugbear.py b/bugbear.py
index c5ec2e4..05dcfac 100644
--- a/bugbear.py
+++ b/bugbear.py
@@ -640,10 +640,15 @@ def empty_body(body) -> bool:
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)
+ isinstance(stmt.value, (ast.Ellipsis, ast.Str))
+ or (
+ isinstance(stmt.value, ast.Constant)
+ and (
+ stmt.value.value is Ellipsis
+ or isinstance(stmt.value.value, str)
+ )
+ )
)
)
for stmt in body
diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py
index e15c926..977bfe5 100644
--- a/tests/test_bugbear.py
+++ b/tests/test_bugbear.py
@@ -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, 7) else 30, 4, vars=("empty_5",)),
)
self.assertEqual(errors, expected)