Skip to content

Diagnostics for invalid await expressions #919

@sharkdp

Description

@sharkdp

We currently don't emit any errors in await xyz expressions if xyz is not awaitable. We should probably do something similar to what we do for iterators or context managers, where we emit helpful diagnostics if calls to respective dunder methods fail. For example:

class NotAwaitable: ...

class NotAwaitable2:
    # not async!
    def __await__(self):
        pass

async def main():
    x = await 1  # should be an error
    y = await NotAwaitable()  # should be an error
    z = await NotAwaitable2()  # should be an error

The entrypoint to implement this is here: https://github.com/astral-sh/ruff/blob/27b03a9d7bf779049585bb6cfbf229f18352572d/crates/ty_python_semantic/src/types.rs#L4868

Metadata

Metadata

Assignees

Labels

diagnosticsRelated to reporting of diagnostics.good first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions