python / python/mypy

`asyncio.gather` is sometimes erroneously type-checked

オープン
#10,682 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-async topic-overloads topic-pep-646
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

I'm adding typing to a large codebase, and have noticed weird asyncio.gather behavior.

To Reproduce

Here's a self-contained test:

from asyncio import gather


async def returns_dict() -> dict:
    return {}


async def returns_int() -> int:
    return 1


async def test():
    tasks = (returns_dict(), returns_int())
    reveal_type(await gather(*tasks))  # note: Revealed type is "Any"

Expected Behavior

The revealed type should be: note: Revealed type is "Tuple[builtins.dict*[Any, Any], builtins.int*]"

Actual Behavior

The correct return type is not recognized.

If the example is slightly changed:

from asyncio import gather


async def returns_dict() -> dict:
    return {}


async def returns_int() -> int:
    return 1


async def test():
    reveal_type(await gather(returns_dict(), returns_int()))

it works properly.

Your Environment

  • Mypy version used: 0.902
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): allow_redefinition, check_untyped_defs, namespace_packages, warn_unreachable
  • Python version used: 3.9.5
  • Operating system and version: macOs Big Sur

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

issue にある自己完結型の asyncio.gather 再現コードから始め、*tasks を指定して渡した tuple と直接の引数について、明らかになる型を比較します。gather 呼び出しの型チェックのエントリーポイントを追跡します。tuple 形式で Any ではなく期待される dict-and-int の結果が明らかになり、既存の直接引数の動作が維持されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。