Mypy complains about the `all_equal` recipe from the itertools docs
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
The following function is given as a recipe in the itertools docs, indicating that it's an idiomatic usage of groupby:
from itertools import groupby
def all_equal(iterable):
g = groupby(iterable)
return next(g, True) and not next(g, False)
I think the correct way of adding type annotations to this function would be as follows, since it will work on arbitrary iterables:
from collections.abc import Iterable
from itertools import groupby
def all_equal(iterable: Iterable[object]) -> bool:
g = groupby(iterable)
return next(g, True) and not next(g, False)
Unfortunately, however, mypy complains about this function:
error: Argument 1 to "next" has incompatible type "groupby[object, object]"; expected "SupportsNext[bool]" [arg-type]
(Mypy gives a similar error if I use Iterable[Any] instead of Iterable[object] for the argument annotation.)
Perhaps we should consider copy-and-pasting all the itertools recipes into our test_cases directory. They're all meant to be idiomatic uses of itertools, so if any of them fail to type check, there's probably a problem somewhere.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提案されている Iterable アノテーションと現在の mypy の動作を使って、itertools のドキュメントにある all_equal レシピを再現します。既存の test_cases ディレクトリを確認し、レシピの型チェックが成功することを完了基準として、そこに itertools のレシピを追加することを検討します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing, tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100