Skip to content

Commit 3401099

Browse files
author
Andrew Bjonnes
committed
Fix bug in fix_raise.py fixer
The replacement node for the fix of a raise statement with an unknown value should inherit the prefix of the source node.
1 parent bcb8513 commit 3401099

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: src/libfuturize/fixes/fix_raise.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def transform(self, node, results):
9494
args = [exc, Comma(), val]
9595
if tb is not None:
9696
args += [Comma(), tb]
97-
return Call(Name(u"raise_"), args)
97+
return Call(Name(u"raise_"), args, prefix=node.prefix)
9898

9999
if tb is not None:
100100
tb.prefix = ""

Diff for: tests/test_future/test_libfuturize_fixers.py

+14
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ def test_unknown_value_with_traceback_with_comments(self):
767767
raise_(E, Func(arg1, arg2, arg3), tb) # foo"""
768768
self.check(b, a)
769769

770+
def test_unknown_value_with_indent(self):
771+
b = """
772+
while True:
773+
print() # another expression in the same block triggers different parsing
774+
raise E, V
775+
"""
776+
a = """
777+
from future.utils import raise_
778+
while True:
779+
print() # another expression in the same block triggers different parsing
780+
raise_(E, V)
781+
"""
782+
self.check(b, a)
783+
770784
# These should produce a warning
771785

772786
def test_string_exc(self):

0 commit comments

Comments
 (0)