'Is it possible to extend class with ParamSpec in Generic in Python?

I have class, with __call__, so I want to specify its arguments in Generic. Also it should return AsyncIterator, so I wrote something like this:

IN = ParamSpec('IN')
OUT = TypeVar('OUT')


class Base(Generic[IN, OUT], metaclass=abc.ABCMeta):
    @abc.abstractmethod
    async def __call__(self,
                       *args: IN.args,
                       **kwargs: IN.kwargs
                       ) -> AsyncIterator[OUT]:
        raise NotImplementedError


class Foo(Base[IN, OUT]):
    def __init__(self, yield_value: OUT):
        self.yield_value = yield_value

    async def __call__(self,
                       *args: IN.args,
                       **kwargs: IN.kwargs
                       ) -> AsyncIterator[OUT]:
        while True:
            yield self.yield_value

And when I ran mypy it gave me 2 errors:

error: ParamSpec "IN" is unbound
error: Return type "AsyncIterator[OUT]" of "__call__" incompatible with return type "Coroutine[Any, Any, AsyncIterator[OUT]]" in supertype "Base"

So what exactly the first error does mean? Also why it says that return type incompatible if annotations exactly the same?

UPD.

The second error can be fixed by removing async from the Base.__call__, not sure is it by design or not.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source