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

Make a Converter without the default hook factories

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

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

The payload names no files. Start with the fallback-hook-factories section of the docs and the unstructure_fallback_factory and structure_fallback_factory arguments of Converter, to see how a child converter consults its parent. Then check why the default structure_attrs_fromdict preference overrides the parent's hook. The issue is open on which approach to take (a BaseConverter workaround or new __init__ flags), so agree on a design with maintainers first. Done means a child converter uses a hook registered on its parent even when a default hook exists.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

The problem

Let's take the fallback-hook-factories section

parent = Converter()

child = Converter(
    unstructure_fallback_factory=parent.get_unstructure_hook,
    structure_fallback_factory=parent.get_structure_hook,
)

Let's say in parent you added another custom hook factory such as

@parent.register_structure_hook_factory(lambda val: issubclass(val, Foo))
def structure_Foo(cls) -> StructureHook:
    ...

You would expect that the child would pick up this new converter of the parent, but that is not the case if there is already a way to structure Foo from the default converters in Converter

So what now?

One way around this is to use BaseConverter I guess, but it is not quite that straightforward and trying it out I still hit some other preferences that override it, e.g. structure_attrs_fromdict.

Another option would be to have flags in the __init__ of those converters to truely not add any defaults and let it fallback to the parent more directly.

Lenguaje dominante
Python
Estrellas
1.1k
Forks
177
Merge medio
14 h 46 min
PR fusionados (30 d)
5

Preparar el entorno

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/cattrs

Todos los issues de python-attrs/cattrs

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.