Skip to content

Allow top-level await in modules compiled with ast.PyCF_ALLOW_TOP_LEVEL_AWAIT #17395

@ntBre

Description

@ntBre

This is related to the await outside async function syntax error, which currently corresponds to await-outside-async (PLE1142). It's not currently an issue because the syntax error is still converted to a PLE1142 diagnostic in ruff, but we'll want to have a plan for handling this before stabilizing it as a syntax error.

This one might not belong in syntax-errors and might be better to remain as a disableable rule. Top level await is allowed if the module is compiled with https://docs.python.org/3/library/ast.html#ast.PyCF_ALLOW_TOP_LEVEL_AWAIT. This is useful when working with pyodide, as modules can assume an event loop is running prior to them being imported.

Originally posted by @mikeshardmind in #17363 (comment)

Metadata

Metadata

Assignees

Labels

needs-designNeeds further design before implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions