Generic Point Free Function Returns Unexpected Type
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
- 35/100
Hướng nghiên cứu
Tái hiện đầu ra của mypy cho test_generic2, tập trung vào entry point bind_result và các chữ ký Callable generic được hiển thị trong báo cáo. So sánh kiểu được suy luận với kết quả IOResult[T4, Exception] mong đợi và xác nhận rằng vấn đề đã được giải quyết khi ví dụ kiểm tra kiểu thành công mà không có lỗi IOResult lồng nhau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
What's wrong
Trying to compose a generic function that converts between different container types fails to type check correctly when using generics. Hopefully I am just using this wrong.
Code:
from typing import Callable, TypeVar
from returns.io import IOResultE
from returns.pointfree import bind_result
from returns.result import ResultE
from typing_extensions import reveal_type
T1 = TypeVar("T1")
T2 = TypeVar("T2")
T3 = TypeVar("T3")
T4 = TypeVar("T4")
# this works correctly
def test(
i: int,
f1: Callable[[int], str],
f2: Callable[[str], IOResultE[int]],
f3: Callable[[int], ResultE[str]],
) -> IOResultE[str]:
f1_res = f1(i)
f2_res = f2(f1_res)
f3_res = bind_result(f3)(f2_res)
reveal_type(f3_res)
return f3_res
# this passes typecheck with returns.io.IOResult[T3`-3, builtins.Exception]
def test_generic(
i: T1,
f1: Callable[[T1], IOResultE[T2]],
f2: Callable[[T2], ResultE[T3]],
) -> IOResultE[T3]:
f1_res = f1(i)
f2_res = bind_result(f2)(f1_res)
reveal_type(f2_res)
return f2_res
# this fails typecheck with returns.io.IOResult[returns.io.IOResult[Any, Any], builtins.Exception]
def test_generic2(
i: T1,
f1: Callable[[T1], T2],
f2: Callable[[T2], IOResultE[T3]],
f3: Callable[[T3], ResultE[T4]],
) -> IOResultE[T4]:
f1_res = f1(i)
f2_res = f2(f1_res)
f3_res = bind_result(f3)(f2_res)
reveal_type(f3_res)
return f3_res
Running mypy:
$ python3 -m mypy test.py
test.py:23: note: Revealed type is "returns.io.IOResult[builtins.str, builtins.Exception]"
test.py:34: note: Revealed type is "returns.io.IOResult[T3`-3, builtins.Exception]"
test.py:47: note: Revealed type is "returns.io.IOResult[returns.io.IOResult[Any, Any], builtins.Exception]"
test.py:48: error: Incompatible return value type (got "IOResult[IOResult[Any, Any], Exception]", expected "IOResult[T4, Exception]")
Found 1 error in 1 file (checked 1 source file)
How is that should be
I would have expected the return type for test_generic2 to be returns.io.IOResult[T4`-3, builtins.Exception]
System information
-
pythonversion: 3.9.12 -
returnsversion: 0.19.0 -
mypyversion: 0.95.0 -
hypothesisversion (if any): -
pytestversion (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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dry-python/returns
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
dry-python/returns#2394 · 1 reaction ·
-
Composing 0-argument functions Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
dry-python/returns#2365 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
dry-python/returns#2355 · 1 bình luận ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
dry-python/returns#2295 · 4 bình luận · 1 reaction ·
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
dry-python/returns#2253 · 2 bình luận ·
Tất cả issue của dry-python/returns
Issue tương tự
-
[Bug] reef-hermes tells me to resume with hermes --resume, which does not work from my shell Đang mởarea: harness bug status: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Human-Agent-Society/reef#625 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
learningequality/kolibri#15351 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Name consistency Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
eellak/triplestore#65 · 1 bình luận ·