From e2d349f781c5f21efe58c9dba7a221f65bcbdb55 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 31 Mar 2020 12:05:39 -0400 Subject: [PATCH] Handle nested async for in for... and Better async comprehension detection. Still more work is needed. See commented-out section in test/simple_source/bug37/02_async_for_generator.py --- test/bytecode_3.7/02_async_for_generator.pyc | Bin 692 -> 991 bytes .../bug37/02_async_for_generator.py | 8 ++ uncompyle6/parsers/parse37base.py | 134 +++++++++++++----- uncompyle6/semantics/customize3.py | 21 ++- uncompyle6/semantics/customize35.py | 11 +- uncompyle6/semantics/pysource.py | 8 +- 6 files changed, 130 insertions(+), 52 deletions(-) diff --git a/test/bytecode_3.7/02_async_for_generator.pyc b/test/bytecode_3.7/02_async_for_generator.pyc index cc9c8b33893eea37eaef355c6b109eb662815f84..935042aaeabf2e68638acf487c1795e81127eea9 100644 GIT binary patch delta 376 zcmXv}%Syvg5S_WXX=6-EmtAz_LWrP0)Qd@RIJxDB~cr(Z)qq zrg244^ZTr)7KsuWLb3ytK;8j;(2xxqwe$))r;;yWcR>(3al*Kl5WzOE0rC^j6V2%U zaLy|_qPO6PjeJc7J^T6I4b9ZrnFdU<7Pp|OhAYPrTNxs9tk_n1GDxk}a>5l4 zt&7Swgyg3IkjwK1y?5>F=rK$4;@~tJCxa~Sp};m7zf5`}ozHLblS*wl^!a>&Zl(_VgcE*g$Xq delta 75 zcmcc5zJ-;~iI= n_colls: + break + if collections[i] == "LOAD_DEREF" and co_flags_is_async(code_obj.co_flags): + self.write(" async") + pass self.write(" for ") self.preorder(store) self.write(" in ") diff --git a/uncompyle6/semantics/customize35.py b/uncompyle6/semantics/customize35.py index 23c3b6d2..62be6b18 100644 --- a/uncompyle6/semantics/customize35.py +++ b/uncompyle6/semantics/customize35.py @@ -16,7 +16,7 @@ """ from xdis.code import iscode -from xdis.util import COMPILER_FLAG_BIT +from xdis.util import co_flags_is_async from uncompyle6.semantics.consts import ( INDENT_PER_LEVEL, PRECEDENCE, @@ -207,14 +207,7 @@ def customize_for_version35(self, version): pass is_code = hasattr(code_node, "attr") and iscode(code_node.attr) - return is_code and ( - code_node.attr.co_flags - & ( - COMPILER_FLAG_BIT["COROUTINE"] - | COMPILER_FLAG_BIT["ITERABLE_COROUTINE"] - | COMPILER_FLAG_BIT["ASYNC_GENERATOR"] - ) - ) + return is_code and co_flags_is_async(code_node.attr.co_flags) def n_function_def(node): if is_async_fn(node): diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 0347f0f0..4cd63a43 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1207,7 +1207,11 @@ class SourceWalker(GenericASTTraversal, object): is_30_dict_comp = False store = None - n = ast[iter_index] + if node == "list_comp_async": + n = ast[2][1] + else: + n = ast[iter_index] + if ast in ( "set_comp_func", "dict_comp_func", @@ -1238,7 +1242,7 @@ class SourceWalker(GenericASTTraversal, object): pass pass elif ast == "listcomp_async": - store = ast[3] + store = ast[2][1] else: assert n == "list_iter", n