From ad345ef94abb502141b35a6c4dc9ba71d66bfdb5 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 9 Jan 2017 07:03:51 -0500 Subject: [PATCH] Add async_call_function for 3.5+ --- test/bytecode_3.5/03_async_await.pyc | Bin 967 -> 1039 bytes test/bytecode_3.6/03_async_await.pyc | Bin 939 -> 1005 bytes test/simple_source/bug35/03_async_await.py | 4 ++-- uncompyle6/parsers/parse3.py | 9 +++++++++ uncompyle6/semantics/pysource.py | 12 +++++++++++- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/test/bytecode_3.5/03_async_await.pyc b/test/bytecode_3.5/03_async_await.pyc index cc528841a5b93569c1e3b6158d0042130e5065a3..291b14e374efa48f23373f103bfd606035be5b64 100644 GIT binary patch delta 404 zcmZXNy-EX75QS&%O*YBK#TdmxBnVb(XJMl+5K{!fCIlg_$$~3#H_ToL{)7}ZcCsu! zLW(?zuOQpnn9fIVCYwU=!u<|2XAbA1@>Z?wdY=3Fl=K#9?Rth#Jk6r`fALR_7|#HA z03(DKg!2(V`%1wSVXDCL4vHPJap|k>@`4k->Tky5&q*7oe4!Yq=g15rSmhl#CgCyBq#lTuggR$l(SddM=zVBIjP9DDyT7*;`>Oh zh^D&iHyAlS7SVOStq!q~-K);2oaE&(MaKTQD9*%kgGpp>2R2OX4$p}=fF4pa`%#^i m)N|ifA*;SscHPs{2glp&b^S6qtmFwAf~G*cf3?{{w|)WdEKFkn delta 308 zcmeC@IL^)~#>>mao@$Sel{ DywNXF diff --git a/test/bytecode_3.6/03_async_await.pyc b/test/bytecode_3.6/03_async_await.pyc index 0d50fe37f0ef1845114f48a1b55f194d5e014c57..97f7ae153b4317ad9706fe8d6377aa3bc58f9a89 100644 GIT binary patch delta 400 zcmZWiK}y3=5dHJNNla?A)-I(8x-d%-LBs^?Lc9(>4TACOI zg9uA=gt3lrCUAk0`Rl&JET9c&=ASPO-YN-=B87Euizm3=v-rBmU=z&Q8N2^baVq0!Pv*^mx1GbdL5aUGuanv@JoM05|o4$@R-KITbMZhv(tN4&79j>Ro j)tailD*M}Ws5W-iNb7k9n#AZbG#Oe9to^Gko>k`uq5MmT delta 308 zcmaFMzM7rWn3tD}%dsdTXCkMM4FeKj0fe2m@!4D!pa+t=SXO;s1 Dspc;# diff --git a/test/simple_source/bug35/03_async_await.py b/test/simple_source/bug35/03_async_await.py index 7dec4df4..19d7ca95 100644 --- a/test/simple_source/bug35/03_async_await.py +++ b/test/simple_source/bug35/03_async_await.py @@ -1,8 +1,8 @@ # Python 3.5+ async and await -async def await_test(): +async def await_test(asyncio): + reader, writer = await asyncio.open_connection(80) await bar() - async def afor_test(): async for i in [1,2,3]: diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 7e122fef..4c421935 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -453,6 +453,15 @@ class Python3Parser(PythonParser): ('kwarg ' * args_kw) + 'expr ' * nak + token.type) self.add_unique_rule(rule, token.type, args_pos, customize) + if self.version >= 3.5: + rule = ('async_call_function ::= expr ' + + ('pos_arg ' * args_pos) + + ('kwarg ' * args_kw) + + 'expr ' * nak + token.type + + ' GET_AWAITABLE LOAD_CONST YIELD_FROM') + self.add_unique_rule(rule, token.type, args_pos, customize) + self.add_unique_rule('expr ::= async_call_function', token.type, args_pos, customize) + rule = ('classdefdeco2 ::= LOAD_BUILD_CLASS mkfunc %s%s_%d' % (('expr ' * (args_pos-1)), opname, args_pos)) self.add_unique_rule(rule, token.type, args_pos, customize) diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 57d80f08..03722cdd 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -332,6 +332,16 @@ class SourceWalker(GenericASTTraversal, object): '%|async with %c as %c:\n%+%c%-', 0, 6, 7), }) + def n_async_call_function(node): + self.f.write('async ') + node.type == 'call_function' + p = self.prec + self.prec = 80 + self.engine(('%c(%P)', 0, (1, -4, ', ', 100)), node) + self.prec = p + self.prune() + self.n_async_call_function = n_async_call_function + def n_funcdef(node): code_node = node[0][1] if (code_node == 'LOAD_CONST' and iscode(code_node.attr) @@ -1589,7 +1599,7 @@ class SourceWalker(GenericASTTraversal, object): beginning of this module for the how we interpret format specifications such as %c, %C, and so on. """ - # self.println("----> ", startnode.type) + # self.println("----> ", startnode.type, ', ', entry[0]) fmt = entry[0] arg = 1 i = 0