Skip to content

Commit

Permalink
Fix bug in fix_raise.py fixer
Browse files Browse the repository at this point in the history
The replacement node for the fix of a raise statement with an unknown
value should inherit the prefix of the source node.
  • Loading branch information
Andrew Bjonnes committed Nov 4, 2021
1 parent bcb8513 commit 3401099
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libfuturize/fixes/fix_raise.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def transform(self, node, results):
args = [exc, Comma(), val]
if tb is not None:
args += [Comma(), tb]
return Call(Name(u"raise_"), args)
return Call(Name(u"raise_"), args, prefix=node.prefix)

if tb is not None:
tb.prefix = ""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_future/test_libfuturize_fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,20 @@ def test_unknown_value_with_traceback_with_comments(self):
raise_(E, Func(arg1, arg2, arg3), tb) # foo"""
self.check(b, a)

def test_unknown_value_with_indent(self):
b = """
while True:
print() # another expression in the same block triggers different parsing
raise E, V
"""
a = """
from future.utils import raise_
while True:
print() # another expression in the same block triggers different parsing
raise_(E, V)
"""
self.check(b, a)

# These should produce a warning

def test_string_exc(self):
Expand Down

0 comments on commit 3401099

Please sign in to comment.