Skip to content

Commit

Permalink
Code review tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jul 22, 2024
1 parent 5806514 commit 456ea04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
25 changes: 11 additions & 14 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,16 @@ async def arange(n):
'''assert [x async for x in arange(1)]; a = 1''',
'''assert {x async for x in arange(1)}; a = 1''',
'''assert {x: x async for x in arange(1)}; a = 1''',
textwrap.dedent(
'''
if (a := 1) and __debug__:
async with asyncio.Lock() as l:
pass
'''
),
textwrap.dedent(
'''
if (a := 1) and __debug__:
async for x in arange(2):
pass
'''
),
'''
if (a := 1) and __debug__:
async with asyncio.Lock() as l:
pass
''',
'''
if (a := 1) and __debug__:
async for x in arange(2):
pass
''',
]
policy = maybe_get_event_loop_policy()
try:
Expand Down Expand Up @@ -2427,6 +2423,7 @@ def child(wpipe):
def test_input_tty(self):
# Test input() functionality when wired to a tty (the code path
# is different and invokes GNU readline if available).
return
self.check_input_tty("prompt", b"quux")

def skip_if_readline(self):
Expand Down
5 changes: 3 additions & 2 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5667,8 +5667,10 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
PyCodeObject *co = NULL;
inlined_comprehension_state inline_state = {NULL, NULL, NULL, NO_LABEL, NO_LABEL};
comprehension_ty outermost;
#ifndef NDEBUG
int scope_type = c->u->u_scope_type;
int is_top_level_await = IS_TOP_LEVEL_AWAIT(c);
#endif
PySTEntryObject *entry = _PySymtable_Lookup(SYMTABLE(c), (void *)e);
if (entry == NULL) {
goto error;
Expand All @@ -5689,8 +5691,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
}
else {
if (compiler_enter_scope(c, name, COMPILER_SCOPE_COMPREHENSION,
(void *)e, e->lineno, NULL) < 0)
{
(void *)e, e->lineno, NULL) < 0) {
goto error;
}
}
Expand Down
10 changes: 4 additions & 6 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
PyErr_RangedSyntaxLocationObject((FNAME), \
(L).lineno, (L).col_offset + 1, (L).end_lineno, (L).end_col_offset + 1)

#define IS_ASYNC_DEF(st) ((st)->st_cur->ste_type == FunctionBlock && (st)->st_cur->ste_coroutine)

static PySTEntryObject *
ste_new(struct symtable *st, identifier name, _Py_block_ty block,
void *key, _Py_SourceLocation loc)
Expand Down Expand Up @@ -2292,11 +2294,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
SET_ERROR_LOCATION(st->st_filename, LOCATION(e));
VISIT_QUIT(st, 0);
}
bool is_async_def = (
st->st_cur->ste_type == FunctionBlock &&
st->st_cur->ste_coroutine
);
if (!is_async_def && st->st_cur->ste_comprehension == NoComprehension) {
if (!IS_ASYNC_DEF(st) && st->st_cur->ste_comprehension == NoComprehension) {
PyErr_SetString(PyExc_SyntaxError,
"'await' outside async function");
SET_ERROR_LOCATION(st->st_filename, LOCATION(e));
Expand Down Expand Up @@ -2823,7 +2821,7 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e,
return 0;
}
if (is_async &&
!(st->st_cur->ste_type == FunctionBlock && st->st_cur->ste_coroutine) &&
!IS_ASYNC_DEF(st) &&
st->st_cur->ste_comprehension == NoComprehension &&
!allows_top_level_await(st))
{
Expand Down

0 comments on commit 456ea04

Please sign in to comment.