From 3438e76865eabd0b9a9396e9248767bcbbdbab7d Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 6 Feb 2020 20:08:00 -0500 Subject: [PATCH] "return locals()" change to track grammar change --- test/bytecode_2.7/05_abc_class.pyc | Bin 568 -> 736 bytes test/simple_source/def/05_abc_class.py | 6 ++++++ uncompyle6/semantics/pysource.py | 23 +++++++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/test/bytecode_2.7/05_abc_class.pyc b/test/bytecode_2.7/05_abc_class.pyc index 936ba1b0baa15a71efc8e19d8aa798078b6c5f88..7e18741e64c5818185ba48b604c23ce9366f2626 100644 GIT binary patch delta 194 zcmdnN@_<#E`7qB!bvM z1jpo8j21>goItiP5Ep}F*ckmF%0R9t;RX`PAcJ#LOEU6Pf`D9xAWon*FE)^3F)jc- C(IB({ delta 77 zcmaFBx`RcU`7 0 and ast[-1][0] == RETURN_LOCALS: + # The function defining a class normally returns locals(). + # We don't want this to show up in the source, so remove the node. + if ast == "stmts" and ast[-1] == "sstmt": + return_locals_parent = ast[-1] + parent_index = 0 + else: + return_locals_parent = ast + parent_index = -1 + return_locals = return_locals_parent[parent_index] + if return_locals == RETURN_LOCALS: if self.hide_internal: - del ast[-1] # remove last node + del return_locals_parent[parent_index] # else: - # print ast[-1][-1] + # print stmt[-1] globals, nonlocals = find_globals_and_nonlocals( ast, set(), set(), code, self.version @@ -2375,8 +2383,11 @@ class SourceWalker(GenericASTTraversal, object): old_name = self.name self.gen_source(ast, code.co_name, code._customize) self.name = old_name + + # save memory by deleting no-longer-used structures code._tokens = None - code._customize = None # save memory + code._customize = None + self.classes.pop(-1) def gen_source(self, ast, name, customize, is_lambda=False, returnNone=False):