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"
|
||||
msgstr ""
|
||||
|
||||
#: py/compile.c
|
||||
msgid "'yield from' inside async function"
|
||||
msgstr ""
|
||||
|
||||
#: py/compile.c
|
||||
msgid "'yield' outside function"
|
||||
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];
|
||||
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
|
||||
@ -1963,7 +1963,7 @@ STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||
// async def
|
||||
compile_funcdef(comp, pns0);
|
||||
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 {
|
||||
// async for/with; first verify the scope is a generator
|
||||
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);
|
||||
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_yield_arg_from)) {
|
||||
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_yield_from(comp);
|
||||
} else {
|
||||
@ -2754,7 +2760,15 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn
|
||||
return;
|
||||
}
|
||||
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
|
||||
|
||||
|
@ -198,16 +198,9 @@ 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
|
||||
// the old behaviour of the u-prefix being used to force a built-in
|
||||
// import.
|
||||
size_t module_name_len;
|
||||
const char *module_name_str = (const char *)qstr_data(module_name, &module_name_len);
|
||||
if (module_name_str[0] != 'u') {
|
||||
// CIRCUITPY-CHANGE: Don't look for `ufoo`.
|
||||
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 found, it's a newly loaded built-in, so init it. This can run
|
||||
|
@ -23,18 +23,11 @@ print(usys, hasattr(usys, "__file__"))
|
||||
# This should get os.py, which uses uos to get the builtin.
|
||||
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.
|
||||
import time
|
||||
|
||||
print(time, hasattr(time, "__file__"), time.sleep, time.extra)
|
||||
|
||||
# These should get the builtins.
|
||||
import uos
|
||||
|
||||
print(uos, hasattr(uos, "__file__"), hasattr(uos, "extra"))
|
||||
|
||||
import utime
|
||||
|
||||
print(utime, hasattr(utime, "__file__"), hasattr(utime, "extra"))
|
||||
# CIRCUITPY-CHANGE: Don't find u prefixes.
|
||||
|
@ -3,8 +3,6 @@
|
||||
<module 'sys'> False
|
||||
<module 'sys'> False
|
||||
os from filesystem
|
||||
<module 'os' from 'ext/os.py'> True / 1
|
||||
<module 'os' from 'ext/os.py'> True
|
||||
time from filesystem
|
||||
<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")
|
||||
|
||||
from uos import *
|
||||
|
||||
extra = 1
|
||||
|
Loading…
Reference in New Issue
Block a user