From 002720988c60406c9de1a09f42b3cb0c100f3459 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 11 Jun 2019 14:08:50 -0400 Subject: [PATCH] Formatting in < 3.0 is different for name ops --- pytest/test_token.py | 6 +++++- pytest/testdata/if-2.7.right | 2 +- pytest/testdata/ifelse-2.7.right | 6 +++--- uncompyle6/scanners/tok.py | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pytest/test_token.py b/pytest/test_token.py index 7c5cb8c0..89173b60 100644 --- a/pytest/test_token.py +++ b/pytest/test_token.py @@ -1,3 +1,4 @@ +from uncompyle6 import PYTHON_VERSION from uncompyle6.scanners.tok import Token def test_token(): @@ -16,7 +17,10 @@ def test_token(): # Make sure formatting of: LOAD_CONST False. We assume False is the 0th index # of co_consts. t = Token('LOAD_CONST', offset=1, attr=False, pattr=False, has_arg=True) - expect = ' 1 LOAD_CONST 0 False' + if PYTHON_VERSION >= 3.0: + expect = ' 1 LOAD_CONST False' + else: + expect = ' 1 LOAD_CONST 0 False' assert t.format() == expect if __name__ == '__main__': diff --git a/pytest/testdata/if-2.7.right b/pytest/testdata/if-2.7.right index 9e315271..bab182cc 100644 --- a/pytest/testdata/if-2.7.right +++ b/pytest/testdata/if-2.7.right @@ -8,5 +8,5 @@ 9 STORE_NAME 2 'b' 12 JUMP_FORWARD 0 'to 15' 15_0 COME_FROM 12 '12' - 15 LOAD_CONST 0 None + 15 LOAD_CONST None 18 RETURN_VALUE diff --git a/pytest/testdata/ifelse-2.7.right b/pytest/testdata/ifelse-2.7.right index 1bfb5aaf..d95c4a13 100644 --- a/pytest/testdata/ifelse-2.7.right +++ b/pytest/testdata/ifelse-2.7.right @@ -4,12 +4,12 @@ 3 0 LOAD_NAME 0 'True' 3 POP_JUMP_IF_FALSE 15 'to 15' - 4 6 LOAD_CONST 0 1 + 4 6 LOAD_CONST 1 9 STORE_NAME 1 'b' 12 JUMP_FORWARD 6 'to 21' - 6 15 LOAD_CONST 1 2 + 6 15 LOAD_CONST 2 18 STORE_NAME 2 'd' 21_0 COME_FROM 12 '12' - 21 LOAD_CONST 2 None + 21 LOAD_CONST None 24 RETURN_VALUE diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index 83750d7d..e558729e 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -118,7 +118,8 @@ class Token(): elif self.op in self.opc.hasvargs: return "%s%s%s" % (prefix, offset_opname, argstr) elif self.op in self.opc.NAME_OPS: - return "%s%s%s %s" % (prefix, offset_opname, argstr, self.attr) + if self.opc.version >= 3.0: + return "%s%s%s %s" % (prefix, offset_opname, argstr, self.attr) elif name == 'EXTENDED_ARG': return "%s%s%s 0x%x << %s = %s" % (prefix, offset_opname, argstr, self.attr, self.opc.EXTENDED_ARG_SHIFT, pattr)