You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Add tuple comma when not in BUILD_LIST_n
Fixes issue #57 bin/uncompile.py: --verify now works on a single bytecode file. We will set the output to be something created by tempfile.mktemps
This commit is contained in:
BIN
test/bytecode_2.7/03_tuple_assign.pyc
Normal file
BIN
test/bytecode_2.7/03_tuple_assign.pyc
Normal file
Binary file not shown.
7
test/simple_source/expression/03_tuple_assign.py
Normal file
7
test/simple_source/expression/03_tuple_assign.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Github Issue #57 with Python 2.7
|
||||||
|
def some_function():
|
||||||
|
return ['some_string']
|
||||||
|
|
||||||
|
def some_other_function():
|
||||||
|
some_variable, = some_function()
|
||||||
|
print(some_variable)
|
@@ -5,7 +5,7 @@
|
|||||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
#
|
#
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys, os, getopt, time
|
import sys, os, getopt, tempfile, time
|
||||||
|
|
||||||
program, ext = os.path.splitext(os.path.basename(__file__))
|
program, ext = os.path.splitext(os.path.basename(__file__))
|
||||||
|
|
||||||
@@ -143,9 +143,12 @@ def main_bin():
|
|||||||
print("No files given", file=sys.stderr)
|
print("No files given", file=sys.stderr)
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
|
||||||
if outfile == '-':
|
if outfile == '-':
|
||||||
outfile = None # use stdout
|
if 'do_verify' in options and len(files) == 1:
|
||||||
|
junk, outfile = tempfile.mkstemp(suffix=".pyc",
|
||||||
|
prefix=files[0][0:-4]+'-')
|
||||||
|
else:
|
||||||
|
outfile = None # use stdout
|
||||||
elif outfile and os.path.isdir(outfile):
|
elif outfile and os.path.isdir(outfile):
|
||||||
out_base = outfile; outfile = None
|
out_base = outfile; outfile = None
|
||||||
elif outfile and len(files) > 1:
|
elif outfile and len(files) > 1:
|
||||||
|
@@ -51,7 +51,9 @@ methods implement most of the below.
|
|||||||
%D same as %C but is for left-recursive lists like kwargs which
|
%D same as %C but is for left-recursive lists like kwargs which
|
||||||
goes to epsilon at the beginning. Using %C an extra separator
|
goes to epsilon at the beginning. Using %C an extra separator
|
||||||
with an epsilon appears at the beginning
|
with an epsilon appears at the beginning
|
||||||
%, print ',' if last %C only printed one item (for tuples--unused)
|
%, print ',' if last %C only printed one item. This is mostly for tuples
|
||||||
|
on the LHS of an assignment statement since BUILD_TUPLE_n pretty-prints
|
||||||
|
other tuples.
|
||||||
%| tab to current indentation level
|
%| tab to current indentation level
|
||||||
%+ increase current indentation level
|
%+ increase current indentation level
|
||||||
%- decrease current indentation level
|
%- decrease current indentation level
|
||||||
@@ -211,7 +213,10 @@ TABLE_DIRECT = {
|
|||||||
'STORE_GLOBAL': ( '%{pattr}', ),
|
'STORE_GLOBAL': ( '%{pattr}', ),
|
||||||
'STORE_DEREF': ( '%{pattr}', ),
|
'STORE_DEREF': ( '%{pattr}', ),
|
||||||
'unpack': ( '%C%,', (1, maxint, ', ') ),
|
'unpack': ( '%C%,', (1, maxint, ', ') ),
|
||||||
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
|
|
||||||
|
# This nonterminal we create on the fly in semantic routines
|
||||||
|
'unpack_w_parens': ( '(%C%,)', (1, maxint, ', ') ),
|
||||||
|
|
||||||
'unpack_list': ( '[%C]', (1, maxint, ', ') ),
|
'unpack_list': ( '[%C]', (1, maxint, ', ') ),
|
||||||
'build_tuple2': ( '%P', (0, -1, ', ', 100) ),
|
'build_tuple2': ( '%P', (0, -1, ', ', 100) ),
|
||||||
|
|
||||||
@@ -1812,9 +1817,12 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
elif typ == '+': self.indentMore()
|
elif typ == '+': self.indentMore()
|
||||||
elif typ == '-': self.indentLess()
|
elif typ == '-': self.indentLess()
|
||||||
elif typ == '|': self.write(self.indent)
|
elif typ == '|': self.write(self.indent)
|
||||||
# no longer used, since BUILD_TUPLE_n is pretty printed:
|
# Used mostly on the LHS of an assignment
|
||||||
|
# BUILD_TUPLE_n is pretty printed and may take care of other uses.
|
||||||
elif typ == ',':
|
elif typ == ',':
|
||||||
pass
|
if (node.type in ('unpack', 'unpack_w_parens') and
|
||||||
|
node[0].attr == 1):
|
||||||
|
self.write(',')
|
||||||
elif typ == 'c':
|
elif typ == 'c':
|
||||||
# FIXME: In Python3 sometimes like from
|
# FIXME: In Python3 sometimes like from
|
||||||
# importfrom
|
# importfrom
|
||||||
|
Reference in New Issue
Block a user