python / python/mypy

Definition Order Matters For `types.coroutine` Decorator

Open
#9,256 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug false-positive topic-async
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

This fails mypy --strict (v0.782):

from types import coroutine
from typing import Any, Iterator

async def my_async_func() -> None:
    await my_coro_func()

@coroutine
def my_coro_func() -> Iterator[None]:
    yield None

but this passes:

from types import coroutine
from typing import Any, Iterator

@coroutine
def my_coro_func() -> Iterator[None]:
    yield None

async def my_async_func() -> None:
    await my_coro_func()

MyPy playground links:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the two minimal examples with mypy --strict on Python 3.8, using the linked passing and failing mypy playgrounds as references. Investigate why moving the types.coroutine-decorated function changes the result; done means both definition orders receive the same correct type-checking result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.