Fix async tests by adding back __await__ use. Remove u* lookup
This commit is contained in:
parent
24b51a21fd
commit
f13ea9a49f
@ -414,6 +414,10 @@ msgstr ""
|
|||||||
msgid "'return' outside function"
|
msgid "'return' outside function"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: py/compile.c
|
||||||
|
msgid "'yield from' inside async function"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: py/compile.c
|
#: py/compile.c
|
||||||
msgid "'yield' outside function"
|
msgid "'yield' outside function"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
20
py/compile.c
20
py/compile.c
@ -923,7 +923,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];
|
mp_parse_node_struct_t *pns0 = (mp_parse_node_struct_t *)pns_body->nodes[0];
|
||||||
body_name = compile_funcdef_helper(comp, pns0, emit_options);
|
body_name = compile_funcdef_helper(comp, pns0, emit_options);
|
||||||
scope_t *fscope = (scope_t *)pns0->nodes[4];
|
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
|
#endif
|
||||||
} else {
|
} else {
|
||||||
assert(MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_classdef); // should be
|
assert(MP_PARSE_NODE_STRUCT_KIND(pns_body) == PN_classdef); // should be
|
||||||
@ -1963,7 +1963,7 @@ STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
|||||||
// async def
|
// async def
|
||||||
compile_funcdef(comp, pns0);
|
compile_funcdef(comp, pns0);
|
||||||
scope_t *fscope = (scope_t *)pns0->nodes[4];
|
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;
|
||||||
} else {
|
} else {
|
||||||
// async for/with; first verify the scope is a generator
|
// async for/with; first verify the scope is a generator
|
||||||
int scope_flags = comp->scope_cur->scope_flags;
|
int scope_flags = comp->scope_cur->scope_flags;
|
||||||
@ -2738,6 +2738,12 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
|||||||
reserve_labels_for_native(comp, 1);
|
reserve_labels_for_native(comp, 1);
|
||||||
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_yield_arg_from)) {
|
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_yield_arg_from)) {
|
||||||
pns = (mp_parse_node_struct_t *)pns->nodes[0];
|
pns = (mp_parse_node_struct_t *)pns->nodes[0];
|
||||||
|
#if MICROPY_PY_ASYNC_AWAIT
|
||||||
|
if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) {
|
||||||
|
compile_syntax_error(comp, (mp_parse_node_t)pns, translate("'yield from' inside async function"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
compile_node(comp, pns->nodes[0]);
|
compile_node(comp, pns->nodes[0]);
|
||||||
compile_yield_from(comp);
|
compile_yield_from(comp);
|
||||||
} else {
|
} else {
|
||||||
@ -2754,7 +2760,15 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
compile_atom_expr_normal(comp, pns);
|
compile_atom_expr_normal(comp, pns);
|
||||||
compile_yield_from(comp);
|
|
||||||
|
// CIRCUITPY-CHANGE: Use __await__ instead of yield from.
|
||||||
|
// 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);
|
||||||
|
EMIT_ARG(yield, MP_EMIT_YIELD_FROM);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -198,15 +198,8 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) {
|
|||||||
// should be using sys.path to force the built-in, but this retains
|
// should be using sys.path to force the built-in, but this retains
|
||||||
// the old behaviour of the u-prefix being used to force a built-in
|
// the old behaviour of the u-prefix being used to force a built-in
|
||||||
// import.
|
// import.
|
||||||
size_t module_name_len;
|
// CIRCUITPY-CHANGE: Don't look for `ufoo`.
|
||||||
const char *module_name_str = (const char *)qstr_data(module_name, &module_name_len);
|
return MP_OBJ_NULL;
|
||||||
if (module_name_str[0] != 'u') {
|
|
||||||
return MP_OBJ_NULL;
|
|
||||||
}
|
|
||||||
elem = mp_map_lookup((mp_map_t *)&mp_builtin_extensible_module_map, MP_OBJ_NEW_QSTR(qstr_from_strn(module_name_str + 1, module_name_len - 1)), MP_MAP_LOOKUP);
|
|
||||||
if (!elem) {
|
|
||||||
return MP_OBJ_NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_MODULE_BUILTIN_INIT
|
#if MICROPY_MODULE_BUILTIN_INIT
|
||||||
|
@ -23,18 +23,11 @@ print(usys, hasattr(usys, "__file__"))
|
|||||||
# This should get os.py, which uses uos to get the builtin.
|
# This should get os.py, which uses uos to get the builtin.
|
||||||
import os
|
import os
|
||||||
|
|
||||||
print(os, hasattr(os, "__file__"), os.sep, os.extra)
|
print(os, hasattr(os, "__file__"))
|
||||||
|
|
||||||
# This should get time.py, which uses empty sys.path to get the builtin.
|
# This should get time.py, which uses empty sys.path to get the builtin.
|
||||||
import time
|
import time
|
||||||
|
|
||||||
print(time, hasattr(time, "__file__"), time.sleep, time.extra)
|
print(time, hasattr(time, "__file__"), time.sleep, time.extra)
|
||||||
|
|
||||||
# These should get the builtins.
|
# CIRCUITPY-CHANGE: Don't find u prefixes.
|
||||||
import uos
|
|
||||||
|
|
||||||
print(uos, hasattr(uos, "__file__"), hasattr(uos, "extra"))
|
|
||||||
|
|
||||||
import utime
|
|
||||||
|
|
||||||
print(utime, hasattr(utime, "__file__"), hasattr(utime, "extra"))
|
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
<module 'sys'> False
|
<module 'sys'> False
|
||||||
<module 'sys'> False
|
<module 'sys'> False
|
||||||
os from filesystem
|
os from filesystem
|
||||||
<module 'os' from 'ext/os.py'> True / 1
|
<module 'os' from 'ext/os.py'> True
|
||||||
time from filesystem
|
time from filesystem
|
||||||
<module 'time' from 'ext/time.py'> True <function> 1
|
<module 'time' from 'ext/time.py'> True <function> 1
|
||||||
<module 'os'> False False
|
|
||||||
<module 'time'> False False
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
print("os from filesystem")
|
print("os from filesystem")
|
||||||
|
|
||||||
from uos import *
|
|
||||||
|
|
||||||
extra = 1
|
extra = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user