From cbd51ebeef7471fb1fd5292db1670276f5eedd6e Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Tue, 27 Jan 2026 19:03:39 +0800 Subject: [PATCH 1/3] warning when await an unawaitable constant --- Python/codegen.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Python/codegen.c b/Python/codegen.c index 478fbec1cbadd0..0394264da75659 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -3748,6 +3748,32 @@ check_index(compiler *c, expr_ty e, expr_ty s) } } +check_awaitable(compiler* c, expr_ty e) +{ + /* Emit a warning when awaiting obvious non-awaitable literal objects. */ + switch (e->kind) { + case Constant_kind: + case Tuple_kind: + case List_kind: + case ListComp_kind: + case Dict_kind: + case DictComp_kind: + case Set_kind: + case SetComp_kind: + case GeneratorExp_kind: + case JoinedStr_kind: + case TemplateStr_kind: + case FormattedValue_kind: + case Interpolation_kind: { + location loc = LOC(e); + return _PyCompile_Warn(c, loc, "'%.200s' object can't be awaited", + infer_type(e)->tp_name); + } + default: + return SUCCESS; + } +} + static int is_import_originated(compiler *c, expr_ty e) { @@ -5295,6 +5321,7 @@ codegen_visit_expr(compiler *c, expr_ty e) ADD_YIELD_FROM(c, loc, 0); break; case Await_kind: + RETURN_IF_ERROR(check_awaitable(c, e->v.Await.value)); VISIT(c, expr, e->v.Await.value); ADDOP_I(c, loc, GET_AWAITABLE, 0); ADDOP_LOAD_CONST(c, loc, Py_None); From 8b360469eea11fe47f1234f5a8a6a53cfeb767ac Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Tue, 27 Jan 2026 19:06:21 +0800 Subject: [PATCH 2/3] add new --- .../2026-01-27-19-06-08.gh-issue-144261.iQANFZ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-01-27-19-06-08.gh-issue-144261.iQANFZ.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-01-27-19-06-08.gh-issue-144261.iQANFZ.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-27-19-06-08.gh-issue-144261.iQANFZ.rst new file mode 100644 index 00000000000000..3482abfd59d311 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-01-27-19-06-08.gh-issue-144261.iQANFZ.rst @@ -0,0 +1 @@ +SyntaxWarning when await an unawaitable constant. From c0ade96a91ab0887ffe926c63adcf298d8cdf19f Mon Sep 17 00:00:00 2001 From: Locked-chess-official <13140752715@163.com> Date: Tue, 27 Jan 2026 19:18:38 +0800 Subject: [PATCH 3/3] add missing type --- Python/codegen.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/codegen.c b/Python/codegen.c index 0394264da75659..9dd081a60fc5f8 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -3748,6 +3748,7 @@ check_index(compiler *c, expr_ty e, expr_ty s) } } +static int check_awaitable(compiler* c, expr_ty e) { /* Emit a warning when awaiting obvious non-awaitable literal objects. */