Suggestion: When eq=Callable, make __hash__ use the return value of the callable.
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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)
- 主要言語
- Python
- スター
- 5.8k
- フォーク
- 480
- 平均マージ
- 2時間 15分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-attrs/attrs のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
python-attrs/attrs#1620 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
python-attrs/attrs#1596 · コメント 2 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
python-attrs/attrs#1549 · コメント 3 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
python-attrs/attrs#1543 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
python-attrs/attrs#1532 ·
python-attrs/attrs の issue をすべて見る
似ている issue
-
area: harness bug status: needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Human-Agent-Society/reef#625 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
learningequality/kolibri#15351 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Name consistency オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
eellak/triplestore#65 · コメント 1 件 ·