Skip to content

Awaitablity checks not fully complete #6053

@Gobot1234

Description

@Gobot1234

Describe the bug
Pyright's checks for whether an object is awaitable are not fully in line with python's. This code runs fine at runtime but type errors

Code or Screenshots

import asyncio
import collections.abc
import contextvars
from typing import Self


class WrapCoro(collections.abc.Coroutine):
    def __init__(self, coro, context):
        self._coro = coro
        self._context = context

    def __await__(self) -> Self:
        return self

    def __iter__(self) -> Self:
        return self

    def __next__(self):
        return self.send(None)

    def throw(self, *exc_info):
        result = self._context.run(self._coro.throw, *exc_info)
        return result

    def send(self, v):
        result = self._context.run(self._coro.send, v)
        return result

async def coro():
    ...

async def foo():
    await WrapCoro(coro(), contextvars.copy_context())  # warning that WrapCoro is not awaitable

asyncio.run(foo())

VS Code extension or command-line
pyright 1.1.328

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions