Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add actual necessary ste_couroutines
  • Loading branch information
Matthias Bussonnier authored and Carreau committed May 21, 2019
commit f48d70ca4a16bbf330b7b9ac4839556ef14f4941
7 changes: 4 additions & 3 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4567,8 +4567,9 @@ compiler_async_with(struct compiler *c, stmt_ty s, int pos)
withitem_ty item = asdl_seq_GET(s->v.AsyncWith.items, pos);

assert(s->kind == AsyncWith_kind);
if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION &&
!(c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT)){
if (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT){
c->u->u_ste->ste_coroutine = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if this c->u->u_ste->ste_coroutine = 1; line is needed? Does it work without it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is necessary, otherwise:

>>> async with acm() as delta:
>>>     count += delta

Traceback (most recent call last):
  File "minirepl.py", line 97, in f
    co = compile(inp, '', 'single', flags=PyCF_ALLOW_TOP_LEVEL_AWAIT)
  File "<string>", line 2
SyntaxError: 'async with' outside async function

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, cool, let's keep it then :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there is be a test in Lib/test/test_builtin.py for that in case you ask.

} else if (c->u->u_scope_type != COMPILER_SCOPE_ASYNC_FUNCTION){
return compiler_error(c, "'async with' outside async function");
}

Expand Down Expand Up @@ -4777,7 +4778,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
ADDOP(c, YIELD_FROM);
break;
case Await_kind:
if (! (c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT)){
if (!(c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT)){
if (c->u->u_ste->ste_type != FunctionBlock){
return compiler_error(c, "'await' outside function");
}
Expand Down