-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
Feature or enhancement
Proposal:
With the advent of Pyodide/PyScript, we have a situation where a Python module gets loaded in async mode with event loop already running, and contains await in module global code, like this:
async def main() -> None:
...
if __name__ == '__main__':
await main()This works fine, however, static code checkers and IDEs get crazy about "you cannot use await in global code", treat it as hard error, highlight the module as erroneous in IDE project etc.
It would be nice to have a universal way to mark a module like "supposed to be used in async context", so that static checkers and IDEs could see that mark and adjust their behavior accordingly.
It can be a # async comment in the first line or from __future__ import asyncmodule or something else statically readable. There's no need for runtime to react on this mark in any way.
PyCF_ALLOW_TOP_LEVEL_AWAIT resolves the situation in runtime, but unfortunately doesn't help in this matter because it's not visible in static context.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
Metadata
Metadata
Assignees
Labels
Projects
Status