From 6b78677a74cdc151019ee5381b422bc9432fc256 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 1 Apr 2018 13:41:16 -0400 Subject: [PATCH] Work on 3.5+ BUILD_MAP_UNPACK... bugs still remain, just reduced. --- test/bytecode_3.5/01_map_unpack.pyc | Bin 313 -> 0 bytes test/bytecode_3.5_run/01_map_unpack.pyc | Bin 0 -> 480 bytes test/simple_source/bug35/01_map_unpack.py | 22 ++++++++++++++++------ uncompyle6/semantics/pysource.py | 14 +++++++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) delete mode 100644 test/bytecode_3.5/01_map_unpack.pyc create mode 100644 test/bytecode_3.5_run/01_map_unpack.pyc diff --git a/test/bytecode_3.5/01_map_unpack.pyc b/test/bytecode_3.5/01_map_unpack.pyc deleted file mode 100644 index 4350096d24c17723292efe5af1ec436923eb93aa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 313 zcmYL?&q~8U5XQgR)TSvE4}##mmt6V>5fn-h^xTW59!f}eLkTv`x@!bMPx=O;@8B!t z>czZ5Pn}V!1K-Tf%+B{a?)AD4=h6Hdz!&Q;TKu|X`3p`t@IfF07=lqS0dn;-S^@8} zX~7)e707_=7yA9(#!Vd7ls3c`H7y&(RZAlwjXJYIS-x9F3DAwMn(HslFZ9$8C3Fa(%DM!cIdz k^@5M!A}+I-T(GzMH+CJK)tyOEnrfX*<-iLyq@y6D9hzJ=TL1t6 diff --git a/test/bytecode_3.5_run/01_map_unpack.pyc b/test/bytecode_3.5_run/01_map_unpack.pyc new file mode 100644 index 0000000000000000000000000000000000000000..57350dc9d9a787f531633054714337797964609b GIT binary patch literal 480 zcmY+9zfJ-{5XQgR4A{R5mn#F?NJ#)RxBX5<}qjLN0LJxyvPzV57W&k$14R zu(tCVuC?M7sGL0@>SpJgx!L*6+#Hrlwp00Zz6kinpOfYIf=z$0_`rhT0A3mo1@ti{ zgeQUoB&&e5;ES|Oz~j&Vd4qJeNX8&OQ`wXvECd`2o&}jcZSn$!ns2B9@Jb+=178E@ zAq$xEKM7nva}P?(-?u}GxUJa<^_ILD66!BS>K_uCE;)j0^5&R)hV6^ilKve+l(ORYUM@x$?rQlU!7O-TMuT1U32EVP19 W#v`w7I9+Bb(mowfm5!(?^5O?a!B`mp literal 0 HcmV?d00001 diff --git a/test/simple_source/bug35/01_map_unpack.py b/test/simple_source/bug35/01_map_unpack.py index 9107e116..33d44ca1 100644 --- a/test/simple_source/bug35/01_map_unpack.py +++ b/test/simple_source/bug35/01_map_unpack.py @@ -1,9 +1,19 @@ # Python 3.5+ PEP 448 - Additional Unpacking Generalizations for dictionaries -{**{}} -{**{'a': 1, 'b': 2}} -## {**{'x': 1}, **{'y': 2}} +# RUNNABLE! +b = {**{}} +assert b == {} +c = {**{'a': 1, 'b': 2}} +assert c == {'a': 1, 'b': 2} +d = {**{'x': 1}, **{'y': 2}} +assert d == {'x': 1, 'y': 2} # {'c': 1, {'d': 2}, **{'e': 3}} [*[]] -{**{0:0 for a in b}} -## {**{}, **{}} -## {**{}, **{}, **{}} + +assert {0: 0} == {**{0:0 for a in c}} + +# FIXME: assert deparsing is incorrect for: +# {**{}, **{}} +# assert {} == {**{}, **{}, **{}} + +# {**{}, **{}, **{}} +# assert {} == {**{}, **{}, **{}} diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index ad785cfd..42496f8a 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1696,7 +1696,8 @@ class SourceWalker(GenericASTTraversal, object): self.indent_more(INDENT_PER_LEVEL) sep = INDENT_PER_LEVEL[:-1] - self.write('{') + if node[0] != 'dict_entry': + self.write('{') line_number = self.line_number if self.version >= 3.0 and not self.is_pypy: @@ -1778,7 +1779,13 @@ class SourceWalker(GenericASTTraversal, object): if sep.startswith(",\n"): self.write(sep[1:]) pass - elif node[-1].kind.startswith('BUILD_MAP_UNPACK'): + elif node[0].kind.startswith('dict_entry'): + assert self.version >= 3.5 + template = ("%C", (0, len(node[0]), ", **")) + self.template_engine(template, node[0]) + sep = '' + elif (node[-1].kind.startswith('BUILD_MAP_UNPACK') + or node[-1].kind.startswith('dict_entry')): assert self.version >= 3.5 # FIXME: I think we can intermingle dict_comp's with other # dictionary kinds of things. The most common though is @@ -1852,7 +1859,8 @@ class SourceWalker(GenericASTTraversal, object): pass if sep.startswith(",\n"): self.write(sep[1:]) - self.write('}') + if node[0] != 'dict_entry': + self.write('}') self.indent_less(INDENT_PER_LEVEL) self.prec = p self.prune()