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

Currying support for generic attrs classes

Đang mở
#1,100 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ó
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
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
backend

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

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

  • python version: 3.7
  • returns version: 0.17.0
  • mypy version: 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

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.