Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

No type error detected when function with wrong type is used in the middle of a pipe

未关闭
#2,253 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
tooling

调研方向

先从复现器开始并运行 mypy,然后检查 returns/_internal/pipeline/pipe.py 和 flow.py 中提到的 pipeline 入口,以及 pipe 使用的类型标注。将此案例与正常工作的第一个参数错误案例进行比较;当 mypy 拒绝不兼容的中间函数且不破坏有效 pipeline 时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug

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

  • python version: 3.12

  • returns version: returns = {extras = ["compatible-mypy"], version = "^0.26.0"}

  • mypy version: mypy = "^1.17.1"

  • hypothesis version (if any):

  • pytest version (if any):

主要语言
Python
星标
4.4k
派生
154
平均合并
3 小时 5 分钟
30 天内合并 PR
22

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

dry-python/returns 的其他 Issue

查看 dry-python/returns 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。