python / python/mypy

Wrong typing warning for map. (Argument X to "map" has incompatible type overloaded function)

オープン
#6,811 コメント 7 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

performance priority-1-normal topic-type-variables
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

I write this function to check the rightmost common element of two list.

this is the code.

import itertools

def get_common_index(*names: str) -> int:
    """zip genalogy history name tag."""

    return max(
        i
        for i, x in enumerate(
            map(
                lambda x: len(set(x)) > 1,
                list(reversed(list(itertools.zip_longest(*map(reversed, names), fillvalue="0")))),
            )
        )
        if x
    )

print(get_common_index("1110111111", "101101111")

It works fine, and the input types are correct.

$ python test.py

5

But mypy raise the following error message.

$ mypy test.py

test.py:24: error: Argument 1 to "map" has incompatible type overloaded function; expected "Callable[[str], Iterator[_T]]"

Is this an error of mypy?

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

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

はじめの一歩

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

調査の方向性

まず、提供された test.py の例で報告を再現し、mypy における map、reversed、itertools.zip_longest のオーバーロードの扱いを調べます。map に渡された callable が互換性のない形で推論される理由を追跡し、有効な入力型ではこの警告が生成されなくなったことを示す回帰テストを追加または更新します。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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