diff --git a/test/bytecode_2.6/04_withas.pyc b/test/bytecode_2.6/04_withas.pyc index 56344384..bfb6e394 100644 Binary files a/test/bytecode_2.6/04_withas.pyc and b/test/bytecode_2.6/04_withas.pyc differ diff --git a/test/bytecode_2.7/03_tuple_assign.pyc b/test/bytecode_2.7/03_tuple_assign.pyc index 01b13823..091b86ba 100644 Binary files a/test/bytecode_2.7/03_tuple_assign.pyc and b/test/bytecode_2.7/03_tuple_assign.pyc differ diff --git a/test/bytecode_2.7/04_withas.pyc b/test/bytecode_2.7/04_withas.pyc index 4223a885..61acd311 100644 Binary files a/test/bytecode_2.7/04_withas.pyc and b/test/bytecode_2.7/04_withas.pyc differ diff --git a/test/bytecode_3.0/04_withas.pyc b/test/bytecode_3.0/04_withas.pyc index 7daa1c3a..f0574c2e 100644 Binary files a/test/bytecode_3.0/04_withas.pyc and b/test/bytecode_3.0/04_withas.pyc differ diff --git a/test/bytecode_3.1/04_withas.pyc b/test/bytecode_3.1/04_withas.pyc index d9c2af12..99ad4503 100644 Binary files a/test/bytecode_3.1/04_withas.pyc and b/test/bytecode_3.1/04_withas.pyc differ diff --git a/test/bytecode_3.3/04_withas.pyc b/test/bytecode_3.3/04_withas.pyc index e1b54e5a..841c708a 100644 Binary files a/test/bytecode_3.3/04_withas.pyc and b/test/bytecode_3.3/04_withas.pyc differ diff --git a/test/simple_source/expression/03_tuple_assign.py b/test/simple_source/expression/03_tuple_assign.py index c89a9173..bc7db24c 100644 --- a/test/simple_source/expression/03_tuple_assign.py +++ b/test/simple_source/expression/03_tuple_assign.py @@ -6,7 +6,12 @@ def some_other_function(): some_variable, = some_function() print(some_variable) +# From 2.7 test_compile.py +# Bug is adding erroneous parens in d[(1:2, 1:2)] += 1 +def bug(d): + d[1:2, 1:2] += 1 + empty_tup = () one_item_tup = ("item1", ) -one_item_tup_without_parentheses = "item", +one_item_tup_without_parentheses = "item", many_items_tup = ("item1", "item2", "item3") diff --git a/test/simple_source/stmts/04_withas.py b/test/simple_source/stmts/04_withas.py index 3ef0be5f..3ce7bad5 100644 --- a/test/simple_source/stmts/04_withas.py +++ b/test/simple_source/stmts/04_withas.py @@ -10,3 +10,9 @@ def formatweekday(self): with self as encoding: return encoding + +# Bug in 2.7.14 test_contextlib.py. Bug was not enclosing (x,y) in parenthesis +def withas_bug(self, nested, a, b): + with self.assertRaises(ZeroDivisionError): + with nested(a(), b()) as (x, y): + 1 // 0 diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 97a9455c..e5a3fa9c 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -140,9 +140,9 @@ TABLE_DIRECT = { 'binary_subscr': ( '%c[%p]', (0, 'expr'), (1, 100) ), - 'binary_subscr2': ( '%c[%p]', + 'binary_subscr2': ( '%c[%c]', (0, 'expr'), - (1, 100) ), + (1, 'expr') ), 'store_subscr': ( '%c[%c]', 0, 1), 'STORE_FAST': ( '%{pattr}', ), 'STORE_NAME': ( '%{pattr}', ), diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 7bb85a1f..ca5202c1 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -315,8 +315,10 @@ class SourceWalker(GenericASTTraversal, object): 'importmultiple': ( '%|import %c%c\n', 2, 3 ), 'import_cont' : ( ', %c', 2 ), # With/as is allowed as "from future" thing in 2.5 + # Note: It is safe to put the variables after "as" in parenthesis, + # and sometimes it is needed. 'withstmt': ( '%|with %c:\n%+%c%-', 0, 3), - 'withasstmt': ( '%|with %c as %c:\n%+%c%-', 0, 2, 3), + 'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3), }) ######################################## @@ -1726,7 +1728,21 @@ class SourceWalker(GenericASTTraversal, object): if lastnodetype.startswith('BUILD_LIST'): self.write('['); endchar = ']' elif lastnodetype.startswith('BUILD_TUPLE'): - self.write('('); endchar = ')' + # Tuples can appear places that can NOT + # have parenthesis around them, like array + # subscripts. We check for that by seeing + # if a tuple item is some sort of slice. + no_parens = False + for n in node: + if n == 'expr' and n[0].kind.startswith('buildslice'): + no_parens = True + break + pass + if no_parens: + endchar = '' + else: + self.write('('); endchar = ')' + pass elif lastnodetype.startswith('BUILD_SET'): self.write('{'); endchar = '}' elif lastnodetype.startswith('BUILD_MAP_UNPACK'):