Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#975 0 comentarios 0 reacciones 0 asignados Ver en GitHub

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

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

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)

Lenguaje dominante
Python
Estrellas
5.8k
Forks
480
Merge medio
2 h 15 min
PR fusionados (30 d)
2

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-attrs/attrs

Todos los issues de python-attrs/attrs

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.