Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore JoinedStr for B018 #216

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,18 +654,15 @@ def check_for_b903(self, node):
self.errors.append(B903(node.lineno, node.col_offset))

def check_for_b018(self, node):
for index, subnode in enumerate(node.body):
for subnode in node.body:
if not isinstance(subnode, ast.Expr):
continue
if index == 0 and isinstance(subnode.value, ast.Str):
continue # most likely a docstring
if isinstance(
subnode.value,
(
ast.Num,
ast.Bytes,
ast.NameConstant,
ast.JoinedStr,
ast.List,
ast.Set,
ast.Dict,
Expand Down
6 changes: 3 additions & 3 deletions tests/b018_classes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Should emit:
B018 - on lines 16-26, 30, 33
B018 - on lines 17-26, 30, 33
"""


Expand All @@ -12,12 +12,12 @@ class Foo2:
"""abc"""

a = 2
"str" # Str
"str" # Str (no raise)
f"{int}" # JoinedStr (no raise)
1j # Number (complex)
1 # Number (int)
1.0 # Number (float)
b"foo" # Binary
f"{int}" # JoinedStr
True # NameConstant (True)
False # NameConstant (False)
None # NameConstant (None)
Expand Down
6 changes: 3 additions & 3 deletions tests/b018_functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Should emit:
B018 - on lines 15-25, 29, 32
B018 - on lines 16-25, 29, 32
"""


Expand All @@ -11,12 +11,12 @@ def foo1():
def foo2():
"""my docstring"""
a = 2
"str" # Str
"str" # Str (no raise)
f"{int}" # JoinedStr (no raise)
1j # Number (complex)
1 # Number (int)
1.0 # Number (float)
b"foo" # Binary
f"{int}" # JoinedStr
True # NameConstant (True)
False # NameConstant (False)
None # NameConstant (None)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_b018_functions(self):
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())

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

expected = [B018(line, 4) for line in range(16, 27)]
expected = [B018(line, 4) for line in range(17, 27)]
expected.append(B018(30, 4))
expected.append(B018(33, 4))
self.assertEqual(errors, self.errors(*expected))
Expand Down