Handle Python 2 vs 3 raise syntax change

raise_stmt ::=  "raise" expression "," expression
becomes:
   raise_stmt ::=  "raise" expression from expression

raise expr, expr -> raise
This commit is contained in:
rocky
2016-08-30 00:39:50 -04:00
parent e4cc126b38
commit 6f2cdc164d
6 changed files with 35 additions and 2 deletions

7
NEWS
View File

@@ -1,3 +1,10 @@
uncompyle6 2.8.2 2016-08-29
- Handle Python 3.6 format string conversions !r, !s, !a
- Start to handle 3.1 bytecode
- Fix some PyPy translation bugs
- We now only handle 3.6.0a3+ since that is incompatible with 3.6 before that
uncompyle6 2.8.1 2016-08-20
- Add Python 2.2 decompilation

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,9 @@
# From 3.4 _pyio.py
# Bug is change in syntax between Python 2 and 3:
# raise_stmt ::= "raise" expression "," expression
# becomes:
# raise_stmt ::= "raise" expression from expression
try:
x = 1
except AttributeError as err:
raise TypeError("an integer is required"), err

View File

@@ -0,0 +1,9 @@
# From 3.4 _pyio.py
# Bug is change in syntax between Python 2 and 3:
# raise_stmt ::= "raise" expression "," expression
# becomes:
# raise_stmt ::= "raise" expression from expression
try:
x = 1
except AttributeError as err:
raise TypeError("an integer is required") from err

View File

@@ -278,7 +278,6 @@ TABLE_DIRECT = {
'raise_stmt0': ( '%|raise\n', ),
'raise_stmt1': ( '%|raise %c\n', 0),
'raise_stmt2': ( '%|raise %c, %c\n', 0, 1),
'raise_stmt3': ( '%|raise %c, %c, %c\n', 0, 1, 2),
# 'yield': ( 'yield %c', 0),
# 'return_stmt': ( '%|return %c\n', 0),
@@ -547,7 +546,16 @@ class SourceWalker(GenericASTTraversal, object):
'DELETE_SLICE+1': ( '%|del %c[%c:]\n', 0, 1 ),
'DELETE_SLICE+2': ( '%|del %c[:%c]\n', 0, 1 ),
'DELETE_SLICE+3': ( '%|del %c[%c:%c]\n', 0, 1, 2 ),
})
})
TABLE_DIRECT.update({
'raise_stmt2': ( '%|raise %c, %c\n', 0, 1),
})
else:
# Gotta love Python for its futzing around with syntax like this
TABLE_DIRECT.update({
'raise_stmt2': ( '%|raise %c from %c\n', 0, 1),
})
if 2.0 <= version <= 2.3:
TABLE_DIRECT.update({