Currying support for generic attrs classes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu tại điểm vào returns.curry.curry và theo dõi cách _eager_curry liên kết các đối số cho class so với các callable thông thường. Tái tạo ví dụ Pair Generic, frozen, keyword-only, sau đó xác minh rằng việc cung cấp b trước và a sau tạo ra Pair(_a=2, _b=1) mà không xảy ra lỗi thiếu đối số.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
I tried out returns, because I was looking for typesafe curry implementation, but I hit a problem with my Generic / Protocol implementing attrs classes.
What's wrong
from typing import TypeVar, Generic
from attr import frozen
from returns.curry import curry
T = TypeVar("T")
@curry
@frozen(kw_only=True)
class Pair(Generic[T]):
_a: T
_b: T
p = Pair(b=1)(a=2)
print(p)
TypeError: __init__() missing 1 required keyword-only argument: 'a'
How is that should be
The above code should simply print
Pair(_a=2, _b=1)
This seems to be due to https://github.com/python-attrs/attrs/issues/374
A fix I hacked together could be something like this.
def curry(function: Callable[..., _ReturnType]) -> Callable[..., _ReturnType]:
import inspect
if inspect.isclass(function):
init_signature = Signature.from_callable(function.__init__)
init_params_without_self = tuple(init_signature.parameters.values())[1:]
argspec = init_signature.replace(parameters=init_params_without_self).bind_partial()
else:
argspec = Signature.from_callable(function).bind_partial()
def decorator(*args, **kwargs):
return _eager_curry(function, argspec, args, kwargs)
return wraps(function)(decorator)
If you are interested in support this admittedly special use case, I could submit a PR.
System information
pythonversion: 3.7returnsversion: 0.17.0mypyversion: 0.910
- 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 confirmed issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
open-webui/open-webui#30750 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100