Standard library map on bound function
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
Bắt đầu với việc tái hiện trong test.py đã được báo cáo, tập trung vào sự tương tác giữa returns.pointfree.bind, ResultE và map tích hợp sẵn của Python. So sánh các kiểu được mypy suy luận với vòng lặp for đang hoạt động và các phương án g tường minh; hoàn tất có nghĩa là ví dụ map(bind(g), map(f, range(3))) ban đầu kiểm tra kiểu mà không có lỗi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
pythonversion: 3.8.6returnsversion: 0.15.0mypyversion: 0.800 (also observed in v0.782 due toclassesslibrary dependency)
- 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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·