You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Keep global statements in fixed order
This commit is contained in:
@@ -128,8 +128,8 @@ def align_deparse_code(version, co, out=sys.stderr, showasm=False, showast=False
|
||||
# What we've been waiting for: Generate Python source from the parse tree!
|
||||
deparsed.gen_source(deparsed.ast, co.co_name, customize)
|
||||
|
||||
for g in deparsed.mod_globs:
|
||||
deparsed.write('# global %s ## Warning: Unused global' % g)
|
||||
for g in sorted(deparsed.mod_globs):
|
||||
deparsed.write('# global %s ## Warning: Unused global\n' % g)
|
||||
|
||||
if deparsed.ERROR:
|
||||
raise SourceWalkerError("Deparsing stopped due to parse error")
|
||||
|
@@ -1768,8 +1768,8 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
||||
deparsed.set_pos_info(deparsed.ast, 0, len(deparsed.text))
|
||||
deparsed.fixup_parents(deparsed.ast, None)
|
||||
|
||||
for g in deparsed.mod_globs:
|
||||
deparsed.write('# global %s ## Warning: Unused global' % g)
|
||||
for g in sorted(deparsed.mod_globs):
|
||||
deparsed.write('# global %s ## Warning: Unused global\n' % g)
|
||||
|
||||
if deparsed.ast_errors:
|
||||
deparsed.write("# NOTE: have decompilation errors.\n")
|
||||
|
@@ -256,7 +256,7 @@ def make_function3_annotate(self, node, is_lambda, nested=1,
|
||||
assert ast == 'stmts'
|
||||
|
||||
all_globals = find_all_globals(ast, set())
|
||||
for g in ((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
for g in sorted((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
self.println(self.indent, 'global ', g)
|
||||
self.mod_globs -= all_globals
|
||||
has_none = 'None' in code.co_names
|
||||
@@ -409,7 +409,7 @@ def make_function2(self, node, is_lambda, nested=1, codeNode=None):
|
||||
assert ast == 'stmts'
|
||||
|
||||
all_globals = find_all_globals(ast, set())
|
||||
for g in ((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
for g in sorted((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
self.println(self.indent, 'global ', g)
|
||||
self.mod_globs -= all_globals
|
||||
has_none = 'None' in code.co_names
|
||||
@@ -655,7 +655,7 @@ def make_function3(self, node, is_lambda, nested=1, codeNode=None):
|
||||
assert ast == 'stmts'
|
||||
|
||||
all_globals = find_all_globals(ast, set())
|
||||
for g in ((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
for g in sorted((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
self.println(self.indent, 'global ', g)
|
||||
self.mod_globs -= all_globals
|
||||
has_none = 'None' in code.co_names
|
||||
|
@@ -2517,7 +2517,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
# Add "global" declaration statements at the top
|
||||
# of the function
|
||||
for g in find_globals(ast, set()):
|
||||
for g in sorted(find_globals(ast, set())):
|
||||
self.println(indent, 'global ', g)
|
||||
|
||||
old_name = self.name
|
||||
@@ -2674,8 +2674,8 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
||||
# What we've been waiting for: Generate source from Syntax Tree!
|
||||
deparsed.gen_source(deparsed.ast, co.co_name, customize)
|
||||
|
||||
for g in deparsed.mod_globs:
|
||||
deparsed.write('# global %s ## Warning: Unused global' % g)
|
||||
for g in sorted(deparsed.mod_globs):
|
||||
deparsed.write('# global %s ## Warning: Unused global\n' % g)
|
||||
|
||||
if deparsed.ast_errors:
|
||||
deparsed.write("# NOTE: have internal decompilation grammar errors.\n")
|
||||
|
Reference in New Issue
Block a user