Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unexpected behavior regarding async generator #5070

Closed
@pawelswiecki

Description

@pawelswiecki

Trying to get typing work in an asynchronous code and I don't understand mypy's behavior.

Let's say we have two coroutines typed in the following way:

fromtypingimportAsyncGeneratorasyncdefgen1()->AsyncGenerator[str,None]:passreveal_type(gen1)asyncdefgen2()->AsyncGenerator[str,None]:yield'tick'reveal_type(gen2)

mypy:

$ mypy file.pyfile.py:5: error: Revealedtype is'def () -> typing.Awaitable[typing.AsyncGenerator[builtins.str, builtins.None]]'file.py:9: error: Revealedtype is'def () -> typing.AsyncGenerator[builtins.str, builtins.None]'

So the type of the first one gets wrapped inAwaitable. I don't fully understand why. I thought allAsync... are Awaitables by definition. I did not find anything about it but here#3576, which is not enough for me to get it.

The same thing in case of methods:

classBaseClass:asyncdefgen1(self)->AsyncGenerator[str,None]:passreveal_type(BaseClass.gen1)classMyClass(BaseClass):asyncdefgen1(self)->AsyncGenerator[str,None]:yield'tick'reveal_type(MyClass.gen1)

mypy:

file.py:4: error: Revealedtype is'def (self: acm.workers.BaseClass) -> typing.Awaitable[typing.AsyncGenerator[builtins.str, builtins.None]]'file.py:7: error: Returntype of"gen1" incompatible with supertype"BaseClass"file.py:9: error: Revealedtype is'def (self: acm.workers.MyClass) -> typing.AsyncGenerator[builtins.str, builtins.None]'

So now I cannot define abstract methods that are async generators, in a straightforward way.

Versions

Python 3.6.5
mypy==0.600

EDIT: I fixed a random typo@JelleZijlstra found and edited parts of the text based on the typo. Now the whole problem is clearer.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp