[Python-checkins] r84276 - in sandbox/trunk/2to3/lib2to3: fixes/fix_raise.py tests/test_fixers.py
benjamin.peterson
python-checkins at python.org
Mon Aug 23 01:51:01 CEST 2010
Author: benjamin.peterson
Date: Mon Aug 23 01:51:01 2010
New Revision: 84276
Log:
when there's a None value and a traceback, don't call type with it #9661
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py Mon Aug 23 01:51:01 2010
@@ -4,6 +4,7 @@
raise E -> raise E
raise E, V -> raise E(V)
raise E, V, T -> raise E(V).with_traceback(T)
+raise E, None, T -> raise E.with_traceback(T)
raise (((E, E'), E''), E'''), V -> raise E(V)
raise "foo", V, T -> warns about string exceptions
@@ -73,7 +74,12 @@
tb = results["tb"].clone()
tb.prefix = u""
- e = Call(exc, args)
+ e = exc
+ # If there's a traceback and None is passed as the value, then don't
+ # add a call, since the user probably just wants to add a
+ # traceback. See issue #9661.
+ if val.type != token.NAME or val.value != u"None":
+ e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb)
new.prefix = node.prefix
Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py Mon Aug 23 01:51:01 2010
@@ -868,6 +868,11 @@
raise Exception(5).with_traceback(6) # foo"""
self.check(b, a)
+ def test_None_value(self):
+ b = """raise Exception(5), None, tb"""
+ a = """raise Exception(5).with_traceback(tb)"""
+ self.check(b, a)
+
def test_tuple_value(self):
b = """raise Exception, (5, 6, 7)"""
a = """raise Exception(5, 6, 7)"""
More information about the Python-checkins
mailing list