[Python-checkins] r54516 - in sandbox/trunk/2to3: fixes/fix_except.py tests/test_fixers.py
collin.winter
python-checkins at python.org
Thu Mar 22 00:02:41 CET 2007
Author: collin.winter
Date: Thu Mar 22 00:02:39 2007
New Revision: 54516
Modified:
sandbox/trunk/2to3/fixes/fix_except.py
sandbox/trunk/2to3/tests/test_fixers.py
Log:
Update fix_except, per Guido's decision that e.args will stay in py3k (http://mail.python.org/pipermail/python-3000/2007-March/006508.html).
Modified: sandbox/trunk/2to3/fixes/fix_except.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_except.py (original)
+++ sandbox/trunk/2to3/fixes/fix_except.py Thu Mar 22 00:02:39 2007
@@ -17,9 +17,7 @@
- "except E, T:" where T is a tuple or list literal:
except E as t:
- T = t.message
-
- This transformation is still under consideration.
+ T = t.args
"""
# Author: Collin Winter
@@ -27,7 +25,7 @@
import pytree
from pgen2 import token
from fixes import basefix
-from fixes.util import Assign, Attr, Name
+from fixes.util import Assign, Attr, Name, is_tuple, is_list
def find_excepts(nodes):
for i, n in enumerate(nodes):
@@ -74,10 +72,10 @@
if isinstance(stmt, pytree.Node):
break
- # The assignment is different if old_N is a tuple
- # In that case, the assignment is old_N = new_N.message
- if str(N).strip()[0] == '(':
- assign = Assign(target, Attr(new_N, Name('message')))
+ # The assignment is different if old_N is a tuple or list
+ # In that case, the assignment is old_N = new_N.args
+ if is_tuple(N) or is_list(N):
+ assign = Assign(target, Attr(new_N, Name('args')))
else:
assign = Assign(target, new_N)
Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/tests/test_fixers.py Thu Mar 22 00:02:39 2007
@@ -497,7 +497,7 @@
try:
pass
except Exception as xxx_todo_changeme:
- (f, e) = xxx_todo_changeme.message
+ (f, e) = xxx_todo_changeme.args
pass
except ImportError as e:
pass"""
@@ -521,14 +521,14 @@
b = """
try:
pass
- except Exception, (a, b):
+ except Exception, [a, b]:
pass"""
a = """
try:
pass
except Exception as xxx_todo_changeme:
- (a, b) = xxx_todo_changeme.message
+ [a, b] = xxx_todo_changeme.args
pass"""
self.check(b, a)
More information about the Python-checkins
mailing list