No type error detected when function with wrong type is used in the middle of a pipe
まだ誰も着手していません。
評価
調査の方向性
再現コードから始めて mypy を実行し、その後、returns/_internal/pipeline/pipe.py と flow.py で言及されているパイプラインのエントリポイントと、pipe で使用されている型付けを調べてください。このケースを、機能している最初の引数のエラーケースと比較してください。mypy が互換性のない途中の関数を拒否し、かつ有効なパイプラインを壊さなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug report
Thank you for this project! I'm new to Python, so I apologize if I've overlooked something.
What's wrong
from collections.abc import Callable
from returns.pipeline import flow, pipe
from returns.pointfree import map_
from returns.result import Success
def get_data(data: str) -> str:
return "200" + data
def do_more(data: int) -> int:
return data - 300
def transform(s: str) -> str:
return f"transformed: {s}"
my_pipe: Callable[[str], str] = pipe(get_data, do_more, transform)
print(flow(Success("500"), map_(my_pipe)))
Gives following runtime error while mypy doesn't complain:
(py-starter) python-boilerplate > python working.py
Traceback (most recent call last):
File "/Users/hoschi/repos/python-boilerplate/working.py", line 22, in <module>
print(flow(Success("500"), map_(my_pipe)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 50, in flow
return reduce( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 51, in <lambda>
lambda composed, function: function(composed), # type: ignore
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/pointfree/map.py", line 55, in factory
return container.map(function)
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/result.py", line 426, in map
return Success(function(self._inner_value))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/pipe.py", line 34, in <lambda>
return lambda instance: flow(instance, *functions)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 50, in flow
return reduce( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/py-starter/lib/python3.12/site-packages/returns/_internal/pipeline/flow.py", line 51, in <lambda>
lambda composed, function: function(composed), # type: ignore
^^^^^^^^^^^^^^^^^^
File "/Users/hoschi/repos/python-boilerplate/working.py", line 13, in do_more
return data - 300
~~~~~^~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'
How is that should be
Mypy should detect the error. It can detect the error when the problem function is used at first arg: pipe(do_more, get_data, transform)
System information
-
pythonversion: 3.12 -
returnsversion:returns = {extras = ["compatible-mypy"], version = "^0.26.0"} -
mypyversion:mypy = "^1.17.1" -
hypothesisversion (if any): -
pytestversion (if any):
- 主要言語
- Python
- スター
- 4.4k
- フォーク
- 154
- 平均マージ
- 3時間 5分
- マージ済み PR(30日)
- 22
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dry-python/returns のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
dry-python/returns#2394 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
dry-python/returns#2365 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
dry-python/returns#2355 · コメント 1 件 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
dry-python/returns#2295 · コメント 4 件 · リアクション 1 件 ·
-
Incorrect result type for `returns.curry.partial` with keyword arguments for positional parameters オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
dry-python/returns#2191 · コメント 1 件 ·
dry-python/returns の issue をすべて見る
似ている issue
-
area: harness bug status: needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Human-Agent-Society/reef#625 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
learningequality/kolibri#15351 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Name consistency オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
eellak/triplestore#65 · コメント 1 件 ·