Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#2,253 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với reproducer và chạy mypy, sau đó kiểm tra các điểm vào của pipeline được đề cập trong returns/_internal/pipeline/pipe.py và flow.py, cùng với kiểu được pipe sử dụng. So sánh trường hợp này với trường hợp lỗi đối số đầu tiên đang hoạt động; được xem là hoàn tất khi mypy từ chối hàm ở giữa không tương thích mà không làm hỏng các pipeline hợp lệ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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):

Ngôn ngữ chính
Python
Star
4.4k
Fork
154
Merge trung bình
3 giờ 5 phút
Pull request đã merge (30 ngày)
22

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dry-python/returns

Tất cả issue của dry-python/returns

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.