summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorKenny <3454741+WarriorOfWire@users.noreply.github.com>2020-10-10 23:39:32 -0700
committerKenny <3454741+WarriorOfWire@users.noreply.github.com>2020-10-10 23:39:32 -0700
commit98aa4b794346161e512d0fba913901021dd2cfbf (patch)
tree8a6dfa086f6ac86d2a2852c7121a3636814a74f7 /py
parent5d96afc5c2e4b4b6aa265a96a3921ac71f036980 (diff)
update async tests with less upython workaround and more cpython compatibility
Diffstat (limited to 'py')
-rw-r--r--py/compile.c12
-rw-r--r--py/objgenerator.c8
2 files changed, 10 insertions, 10 deletions
diff --git a/py/compile.c b/py/compile.c
index da31846e2..45a586594 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -40,6 +40,8 @@
#if MICROPY_ENABLE_COMPILER
+#define DEBUG_PRINT(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
+
// TODO need to mangle __attr names
#define INVALID_LABEL (0xffff)
@@ -853,7 +855,7 @@ STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t *pns0 = (mp_parse_node_struct_t*)pns_body->nodes[0];
body_name = compile_funcdef_helper(comp, pns0, emit_options);
scope_t *fscope = (scope_t*)pns0->nodes[4];
- fscope->scope_flags |= MP_SCOPE_FLAG_GENERATOR;
+ fscope->scope_flags |= MP_SCOPE_FLAG_GENERATOR | MP_SCOPE_FLAG_ASYNC;
#endif
} else {
assert(MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_classdef); // should be
@@ -2655,11 +2657,13 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn
compile_require_async_context(comp, pns);
compile_atom_expr_normal(comp, pns);
-
+ // If it's an awaitable thing, need to reach for the __await__ method for the coroutine.
+ // async def functions' __await__ return themselves, which are able to receive a send(),
+ // while other types with custom __await__ implementations return async generators.
EMIT_ARG(load_method, MP_QSTR___await__, false);
EMIT_ARG(call_method, 0, 0, 0);
- // EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); // don't yield anything from an awaitable; only return the final result.
- // EMIT_ARG(yield, MP_EMIT_YIELD_FROM);
+ EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
+ EMIT_ARG(yield, MP_EMIT_YIELD_FROM);
}
#endif
diff --git a/py/objgenerator.c b/py/objgenerator.c
index baa6a9849..5e651ac26 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -234,12 +234,8 @@ STATIC mp_obj_t gen_instance_await(mp_obj_t self_in) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_AttributeError,
translate("type object 'generator' has no attribute '__await__'")));
}
- mp_obj_t ret = gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL);
- if (ret == MP_OBJ_STOP_ITERATION) {
- nlr_raise(mp_obj_new_exception(&mp_type_StopIteration));
- } else {
- return ret;
- }
+ // You can directly call send on a coroutine generator or you can __await__ then send on the return of that.
+ return self;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_await_obj, gen_instance_await);
#endif