Suggestion: When eq=Callable, make __hash__ use the return value of the callable.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- developer-experience
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- Python
- Estrellas
- 5.8k
- Forks
- 480
- Merge medio
- 2 h 15 min
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python-attrs/attrs
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
python-attrs/attrs#1620 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
python-attrs/attrs#1596 · 2 comentarios · 1 reacción ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
python-attrs/attrs#1549 · 3 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
python-attrs/attrs#1543 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
python-attrs/attrs#1532 ·
Todos los issues de python-attrs/attrs
Issues similares
-
[Bug] reef-hermes tells me to resume with hermes --resume, which does not work from my shell Abiertoarea: harness bug status: needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Human-Agent-Society/reef#625 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
learningequality/kolibri#15351 · 2 comentarios ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Name consistency Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
eellak/triplestore#65 · 1 comentario ·