Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Feature request: "flatten" operation for cattrs.gen

Ouverte
#352 0 commentaires 3 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
backend

Piste de recherche

Start by reading the existing override function and the make_dict_structure_fn and make_dict_unstructure_fn entry points. Trace how field overrides are applied in both directions, then define the flatten behavior around the provided A and C example. Done means the proposed flatten option works for structure and unstructure while preserving existing behavior by default.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

For a thing at work, I implemented some [un]structure hook factories that wrap make_dict_structure_fn and make_dict_unstructure_fn to support flattening an attribute, like this:

@define
class A:
    a: int
    b: int

@define
class C:
    a: A
    c: int

converter = ...  # set up a converter with my wrappers

assert converter.unstructure(C(A(1, 2), 3)) == {'a': 1, 'b': 2, 'c': 3}

I'd like to upstream this support. The basic idea is to implement functionality similar to Serde's Struct flattening by extending the override function to take a flatten: bool argument that defaults to False and then adjusting make_dict_structure_fn and make_dict_unstructure_fn to use it.

I'm willing to work on this, but wanted to get feedback from folks here before I start.

Langage dominant
Python
Étoiles
1.1k
Forks
165
Merge moyen
11 h 51 min
PR mergées (30 j)
7

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-attrs/cattrs

Toutes les issues de python-attrs/cattrs

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.