X Tutup
Skip to content

Commit d2b477a

Browse files
committed
Add tuple comma when not in BUILD_LIST_n
Fixes issue rocky#57 bin/uncompile.py: --verify now works on a single bytecode file. We will set the output to be something created by tempfile.mktemps
1 parent 6908898 commit d2b477a

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed
485 Bytes
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Github Issue #57 with Python 2.7
2+
def some_function():
3+
return ['some_string']
4+
5+
def some_other_function():
6+
some_variable, = some_function()
7+
print(some_variable)

uncompyle6/bin/uncompile.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
66
#
77
from __future__ import print_function
8-
import sys, os, getopt, time
8+
import sys, os, getopt, tempfile, time
99

1010
program, ext = os.path.splitext(os.path.basename(__file__))
1111

@@ -143,9 +143,12 @@ def main_bin():
143143
print("No files given", file=sys.stderr)
144144
usage()
145145

146-
147146
if outfile == '-':
148-
outfile = None # use stdout
147+
if 'do_verify' in options and len(files) == 1:
148+
junk, outfile = tempfile.mkstemp(suffix=".pyc",
149+
prefix=files[0][0:-4]+'-')
150+
else:
151+
outfile = None # use stdout
149152
elif outfile and os.path.isdir(outfile):
150153
out_base = outfile; outfile = None
151154
elif outfile and len(files) > 1:

uncompyle6/semantics/pysource.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
%D same as %C but is for left-recursive lists like kwargs which
5252
goes to epsilon at the beginning. Using %C an extra separator
5353
with an epsilon appears at the beginning
54-
%, print ',' if last %C only printed one item (for tuples--unused)
54+
%, print ',' if last %C only printed one item. This is mostly for tuples
55+
on the LHS of an assignment statement since BUILD_TUPLE_n pretty-prints
56+
other tuples.
5557
%| tab to current indentation level
5658
%+ increase current indentation level
5759
%- decrease current indentation level
@@ -211,7 +213,10 @@
211213
'STORE_GLOBAL': ( '%{pattr}', ),
212214
'STORE_DEREF': ( '%{pattr}', ),
213215
'unpack': ( '%C%,', (1, maxint, ', ') ),
214-
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
216+
217+
# This nonterminal we create on the fly in semantic routines
218+
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
219+
215220
'unpack_list': ( '[%C]', (1, maxint, ', ') ),
216221
'build_tuple2': ( '%P', (0, -1, ', ', 100) ),
217222

@@ -1812,9 +1817,12 @@ def engine(self, entry, startnode):
18121817
elif typ == '+': self.indentMore()
18131818
elif typ == '-': self.indentLess()
18141819
elif typ == '|': self.write(self.indent)
1815-
# no longer used, since BUILD_TUPLE_n is pretty printed:
1820+
# Used mostly on the LHS of an assignment
1821+
# BUILD_TUPLE_n is pretty printed and may take care of other uses.
18161822
elif typ == ',':
1817-
pass
1823+
if (node.type in ('unpack', 'unpack_w_parens') and
1824+
node[0].attr == 1):
1825+
self.write(',')
18181826
elif typ == 'c':
18191827
# FIXME: In Python3 sometimes like from
18201828
# importfrom

0 commit comments

Comments
 (0)
X Tutup