Suggestion: When eq=Callable, make __hash__ use the return value of the callable.
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ả
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
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 python-attrs/attrs
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
python-attrs/attrs#1620 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
python-attrs/attrs#1596 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
python-attrs/attrs#1549 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
python-attrs/attrs#1543 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
python-attrs/attrs#1532 ·
Tất cả issue của python-attrs/attrs
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 ·