Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
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
base:main
Are you sure you want to change the base?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SyntaxWarning when await an unawaitable constant. | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This requires better phrasing. This does not explain anything. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| { | ||
| @@ -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); | ||
Uh oh!
There was an error while loading.Please reload this page.