Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Standard library map on bound function

オープン
#807 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

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

調査の方向性

報告されている test.py の再現から始め、returns.pointfree.bind、ResultE、Python 組み込みの map の相互作用に焦点を当てます。mypy が推論した型を、動作する for ループおよび明示的な g の代替案と比較します。完了の条件は、元の map(bind(g), map(f, range(3))) の例がエラーなしで型チェックを通ることです。

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

説明

bug

Bug report

Mypy does not appear to correctly handle the standard library map function over an iterable of containers that returns an iterable of containers, when the function being mapped over the data has had returns.pointfree.bind applied to it. The same code when used without map (by explicit use of a for-loop) or a bind (by explicitly handling a container input) will not result in an error.

What's wrong

Code to reproduce issue
from typing import Iterable

from returns.pointfree import bind
from returns.result import ResultE
from returns.result import safe


@safe
def f(x: int) -> str:
    return str(x)


@safe
def g(x: str) -> int:
    return int(x)


def h(xs: Iterable[ResultE[int]]) -> None:
    for x in xs:
        print(x.unwrap())


if __name__ == "__main__":
    h(map(bind(g), map(f, range(3))))
Mypy output
$ mypy test.py
test.py:24:11: error: Argument 1 to "map" has incompatible type "Kinded[Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Result[Any, Any], int, Exception, NoReturn]]]"; expected "Callable[[Result[str, Exception]], Res
ult[int, Exception]]"  [arg-type]
test.py:24:11: note: "Kinded[Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Result[Any, Any], int, Exception, NoReturn]]].__call__" has type "Callable[[KindN[Result[Any, Any], str, Exception, NoReturn]], KindN[Resul
t[Any, Any], int, Exception, NoReturn]]"
Found 1 error in 1 file (checked 1 source file)
Python output
$ python test.py
0
1
2

How it should be

When the h function is replaced with a for-loop in __main__ no issues are reported by Mypy and the code executes correctly:

if __name__ == "__main__":
    for x in map(f, range(3)):
        print(x.bind(g).unwrap())

Can also fix the issue by swapping out the g function:

def g(x: ResultE[str]) -> ResultE[int]:
    return x.map(int)

<snip>

if __name__ == "__main__":
    h(map(g, map(f, range(3))))

System information

  • python version: 3.8.6
  • returns version: 0.15.0
  • mypy version: 0.800 (also observed in v0.782 due to classess library dependency)
主要言語
Python
スター
4.4k
フォーク
154
平均マージ
3時間 5分
マージ済み PR(30日)
22

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

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

はじめの一歩

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

dry-python/returns のほかの issue

dry-python/returns の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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