Skip to content

Commit 6fb81ee

Browse files
authored
Ignore JoinedStr for B018 (#216)
* Ignore JoinedStr for B018 * Improve tests * Fix bug
1 parent c0a9c87 commit 6fb81ee

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

Diff for: bugbear.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -654,18 +654,15 @@ def check_for_b903(self, node):
654654
self.errors.append(B903(node.lineno, node.col_offset))
655655

656656
def check_for_b018(self, node):
657-
for index, subnode in enumerate(node.body):
657+
for subnode in node.body:
658658
if not isinstance(subnode, ast.Expr):
659659
continue
660-
if index == 0 and isinstance(subnode.value, ast.Str):
661-
continue # most likely a docstring
662660
if isinstance(
663661
subnode.value,
664662
(
665663
ast.Num,
666664
ast.Bytes,
667665
ast.NameConstant,
668-
ast.JoinedStr,
669666
ast.List,
670667
ast.Set,
671668
ast.Dict,

Diff for: tests/b018_classes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Should emit:
3-
B018 - on lines 16-26, 30, 33
3+
B018 - on lines 17-26, 30, 33
44
"""
55

66

@@ -12,12 +12,12 @@ class Foo2:
1212
"""abc"""
1313

1414
a = 2
15-
"str" # Str
15+
"str" # Str (no raise)
16+
f"{int}" # JoinedStr (no raise)
1617
1j # Number (complex)
1718
1 # Number (int)
1819
1.0 # Number (float)
1920
b"foo" # Binary
20-
f"{int}" # JoinedStr
2121
True # NameConstant (True)
2222
False # NameConstant (False)
2323
None # NameConstant (None)

Diff for: tests/b018_functions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Should emit:
3-
B018 - on lines 15-25, 29, 32
3+
B018 - on lines 16-25, 29, 32
44
"""
55

66

@@ -11,12 +11,12 @@ def foo1():
1111
def foo2():
1212
"""my docstring"""
1313
a = 2
14-
"str" # Str
14+
"str" # Str (no raise)
15+
f"{int}" # JoinedStr (no raise)
1516
1j # Number (complex)
1617
1 # Number (int)
1718
1.0 # Number (float)
1819
b"foo" # Binary
19-
f"{int}" # JoinedStr
2020
True # NameConstant (True)
2121
False # NameConstant (False)
2222
None # NameConstant (None)

Diff for: tests/test_bugbear.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def test_b018_functions(self):
234234
bbc = BugBearChecker(filename=str(filename))
235235
errors = list(bbc.run())
236236

237-
expected = [B018(line, 4) for line in range(15, 26)]
237+
expected = [B018(line, 4) for line in range(16, 26)]
238238
expected.append(B018(29, 4))
239239
expected.append(B018(32, 4))
240240
self.assertEqual(errors, self.errors(*expected))
@@ -244,7 +244,7 @@ def test_b018_classes(self):
244244
bbc = BugBearChecker(filename=str(filename))
245245
errors = list(bbc.run())
246246

247-
expected = [B018(line, 4) for line in range(16, 27)]
247+
expected = [B018(line, 4) for line in range(17, 27)]
248248
expected.append(B018(30, 4))
249249
expected.append(B018(33, 4))
250250
self.assertEqual(errors, self.errors(*expected))

0 commit comments

Comments
 (0)