Skip to content

Python: treat await expressions as side-effecting - #23030

Open
baywet wants to merge 1 commit into
github:mainfrom
baywet:fix-python-await-side-effects
Open

baywet wants to merge 1 commit into
github:mainfrom
baywet:fix-python-await-side-effects

Conversation

@baywet

@baywet baywet commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treat Python Await expressions as side-effecting, consistent with yield and yield from.
  • Prevent py/ineffectual-statement from flagging an awaited task or coroutine merely because its returned value is discarded.
  • Add regression cases for value-returning tasks and coroutines, plus a library change note.

Example false positive: microsoft/agent-framework#8662 (comment)

Validation

  • Confirmed both new cases were reported before the fix.
  • After the fix, both tests in python/ql/test/query-tests/Statements/no_effect pass using CodeQL CLI 2.27.4 in a Linux ARM64 Docker container.
  • codeql query format --check-only and git diff --check pass.
  • No expected-result files changed.

Prevent ineffectual-statement false positives when awaiting a task or coroutine without assigning its returned value. Add regression cases for both forms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f0800d30-e4f9-463c-a0d8-660fe1aceaf1
@baywet
baywet marked this pull request as ready for review November 5, 2026 14:46
@baywet
baywet requested a review from a team as a code owner November 5, 2026 14:46
Copilot AI auto review requested due to automatic review settings November 5, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the change to treat Python await expressions as side-effecting.

No open issues 🎉

What changed in this PR

This PR updates Python’s side-effect analysis so py/ineffectual-statement no longer flags await expressions merely because their results are discarded.

Changes:

  • Mark Await expressions as side-effecting, consistent with yield and yield from.
  • Add regression cases for awaiting value-returning tasks and coroutines.
  • Document the analysis change in a library change note.
File Description
python/​ql/​test/​query-tests/​Statements/​no_effect/​await_task.py Adds task and coroutine regression cases.
python/​ql/​lib/​semmle/​python/​Exprs.qll Makes Await.hasSideEffects() always hold.
python/​ql/​lib/​change-notes/​2026-11-05-await-side-effects.md Documents the false-positive fix.

Review effort: Balanced (auto)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants