From 6d368d2b30be477edd8a2a8447baddc7b609b806 Mon Sep 17 00:00:00 2001 From: rocky Date: Thu, 16 Jan 2020 22:15:28 -0500 Subject: [PATCH] parens around consts when taking attr again --- test/bytecode_3.7/01_class.pyc | Bin 393 -> 0 bytes test/bytecode_3.7_run/01_class.pyc | Bin 0 -> 827 bytes test/bytecode_3.8_run/01_class.pyc | Bin 0 -> 835 bytes test/simple_source/def/01_class.py | 11 +++++++++++ uncompyle6/semantics/consts.py | 4 ++++ uncompyle6/semantics/pysource.py | 11 +++++++++++ 6 files changed, 26 insertions(+) delete mode 100644 test/bytecode_3.7/01_class.pyc create mode 100644 test/bytecode_3.7_run/01_class.pyc create mode 100644 test/bytecode_3.8_run/01_class.pyc diff --git a/test/bytecode_3.7/01_class.pyc b/test/bytecode_3.7/01_class.pyc deleted file mode 100644 index 563005a98b541c3d52a9a89009a7a917a3cc99fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 393 zcmZ?d<>g`kg58=YqWl;c7#@Q-Fu($2H~?|65|D6bNMT4}YyskCrYI1PDTNuxV@_pk zW{zS?VF_l?WK9ODg9D&x5ZydLMk+%TV+sRM9V1X3(=A3vKTYOa9P#maiMgrq@wd3* z<8$*>z=@f)QfO5q*4oj`dS<@)W@dhHFk*Pl?%#WNE*Sek#_mL@%<#I$D9)K;ihskq z6$M#BNwlQqTUiLSBNd|^Yl(KGl9wzWtT68KaMWga-98G<3a(fo6h}YN@smX^yA;4I z*BYQ30jz7)R;2F(d~TOj|K~fiF@^{6>#i%;4f?pcwJUw3^oOHI$FQoF&P|(*B|yS* z$cv>s*#BSA94oREX(b8j#UJQiOXzKY;uhW=3fWgsQhb<^!!r~+-qzr@**RzQy=6wc!5(AJk}iI+d2aj_sLK{l{(@4xkV;^P zyx0pN(;x$dMIK$_*bM<(ReJ|;BVA&1NNoD1{v^n=i{tlgS^3gre$!}|soFg7nQNP- zwmyS?Bmfx>ru=Bu+W6@rPp>1((s)bxsfI8`oc{R4IcmxE8S4mFh9G8-ofLhq+R-?U&g0ln`jfpauWRp1W1_) literal 0 HcmV?d00001 diff --git a/test/bytecode_3.8_run/01_class.pyc b/test/bytecode_3.8_run/01_class.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ed39a017e6b744b3801cf532879c4bf0f912500d GIT binary patch literal 835 zcmb7C&2G~`5Z)i#aY7p+QE@{u7f>XWQqBmamD<7qUjP9jJu~0@z1ZCyF+3-CZofGdjD00=@k9vbDDDBOQ>K{WUr@H9 zAS9GTBsJg4LLiP*j5yX3aio%GY&uw?-yeq~nxnWKRGJlBu|g=0wxZ*Q`I+oe0JB(W zfNlh^s#ROjeFxxUyQumY_U|9SvRXJdYu1(siOXSq zEad_JUsgxCCEwqa{cS*RDXQxz=g|pYicXJnGJ1^ayk_hd){gyReZMw0b)*EuO1gVK zQPGxv<}aDqi>~)<1NLf9KsZF`r||AwDo0ej;*b2H++r^;rh??ZcutO x_>@nC;0d4bF%NV~3*Ia;y~7FPxB(ue&rJ__4Jts2Wo^aBl*n5X~% literal 0 HcmV?d00001 diff --git a/test/simple_source/def/01_class.py b/test/simple_source/def/01_class.py index 555f7f06..8d98daf1 100644 --- a/test/simple_source/def/01_class.py +++ b/test/simple_source/def/01_class.py @@ -8,8 +8,19 @@ # classdef ::= LOAD_CONST expr mkfunc CALL_FUNCTION_0 BUILD_CLASS store # mkfunc ::= LOAD_CONST MAKE_FUNCTION_0 +# RUNNABLE! class A: pass class B(Exception): pass + +# From 3.x test_descr.py +class MyInt(int): + class MyInt(int): + __slots__ = () + try: + (1).__class__ = MyInt + assert False, "builtin types don't support __class__ assignment." + except TypeError: + pass diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 933a842d..b7a3ba94 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -268,6 +268,10 @@ TABLE_DIRECT = { 'attribute_w_parens': ( '(%c).%[1]{pattr}', (0, 'expr')), + # This nonterminal we create on the fly in semantic routines + 'store_w_parens': ( '(%c).%[1]{pattr}', + (0, 'expr')), + 'unpack_list': ( '[%C]', (1, maxint, ', ') ), 'build_tuple2': ( '%P', diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 54b243c7..aee16400 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1889,6 +1889,17 @@ class SourceWalker(GenericASTTraversal, object): n_set = n_tuple = n_build_set = n_list + def n_store(self, node): + expr = node[0] + if expr == "expr" and expr[0] == "LOAD_CONST" and node[1] == "STORE_ATTR": + # FIXME: I didn't record which constants parenthesis is + # necessary. However, I suspect that we could further + # refine this by looking at operator precedence and + # eval'ing the constant value (pattr) and comparing with + # the type of the constant. + node.kind = "store_w_parens" + self.default(node) + def n_unpack(self, node): if node[0].kind.startswith("UNPACK_EX"): # Python 3+