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

Suggestion: When eq=Callable, make __hash__ use the return value of the callable.

Đang mở
#975 0 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
42/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
developer-experience

Hướng nghiên cứu

Start by tracing how attrs.field(eq=...) is interpreted for an @attrs.frozen class and how the generated hash handles that field. Compare the proposed hash=True and hash=key_func APIs, then add focused coverage showing that equality and hashing remain consistent; done means the example can be used as a dictionary key without a custom hash.

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

Mô tả

Feature

The specific situation is more complicated, but this is the minimal representation. I have a situation where I have a datastructure that is "frozen" and my contract with myself is I promise not to edit any of the values in it. But I can't use the attrs datastructure as a dict key because a field is mutable and unhashable.

def key_func(field: dict[str, str]):
  return sorted(field.keys())

@attrs.frozen
class Example:
  other: int
  field: dict[str, str]: attrs.field(eq=key_func)

I've "solved" this by adding the hash method:

  def __hash__(self):
    return hash((self.other, key_func(self.field)))

But it would be nice if we could do this natively via the API.

If necessary, either of these incantations seem sensible: attrs.field(eq=key_func, hash=True) or attrs.field(eq=key_func, hash=key_func)

Ngôn ngữ chính
Python
Star
5.8k
Fork
480
Merge trung bình
2 giờ 15 phút
Pull request đã merge (30 ngày)
2

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 python-attrs/attrs

Tất cả issue của python-attrs/attrs

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.