Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144261: SyntaxWarning when await an unawaitable constant#144271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Locked-chess-official wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromLocked-chess-official:await_warning
Draft
Show file tree
Hide file tree
Changes fromall commits
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
SyntaxWarning when await an unawaitable constant.
Copy link
Member

Choose a reason for hiding this comment

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

This requires better phrasing. This does not explain anything.

28 changes: 28 additions & 0 deletionsPython/codegen.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3748,6 +3748,33 @@ 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. */
switch (e->kind) {
Copy link
Member

Choose a reason for hiding this comment

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

It's better to swap the kinds and only consider kinds that are awaitable. Otherwise, we need to update that list whenever we add a new kind that is not awaitable.

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)
{
Expand DownExpand Up@@ -5295,6 +5322,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);
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp