Skip to content
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ Future
functions that are ignored by the B906 check. The ``ast.Bytes``, ``ast.Num`` and
``ast.Str`` nodes are all deprecated, but may still be used by some codebases in
order to maintain backwards compatibility with Python 3.7.
* B016: Warn when raising f-strings.

23.1.20
~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def check_for_b015(self, node):
self.errors.append(B015(node.lineno, node.col_offset))

def check_for_b016(self, node):
if isinstance(node.exc, (ast.NameConstant, ast.Num, ast.Str)):
if isinstance(node.exc, (ast.NameConstant, ast.Num, ast.Str, ast.JoinedStr)):
self.errors.append(B016(node.lineno, node.col_offset))

def check_for_b017(self, node):
Expand Down
5 changes: 4 additions & 1 deletion tests/b016.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""
Should emit:
B016 - on lines 6, 7, and 8
B016 - on lines 6, 7, 8, and 10
"""

raise False
raise 1
raise "string"
fstring = "fstring"
raise f"fstring {fstring}"
raise Exception(False)
raise Exception(1)
raise Exception("string")
raise Exception(f"fstring {fstring}")
2 changes: 1 addition & 1 deletion tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_b016(self):
filename = Path(__file__).absolute().parent / "b016.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = self.errors(B016(6, 0), B016(7, 0), B016(8, 0))
expected = self.errors(B016(6, 0), B016(7, 0), B016(8, 0), B016(10, 0))
self.assertEqual(errors, expected)

def test_b017(self):
Expand Down