Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Option to include `init=False` globally on a converter, not per class

Offen
#482 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
backend

Rechercherichtung

Start with cattrs.Converter and the cattrs.strategies.include_init_false entry point mentioned in the issue, then inspect how converter configuration affects attrs classes. Verify the chosen global option with structure and unstructure examples containing init=False fields, and add coverage showing the old behavior is enabled for multiple classes.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

documentation
  • cattrs version: v23.2.3
  • Python version: 3.11.6
  • Operating System: Ubuntu
Description

On previous cattrs versions, I used to structure and unstructure a lot of attrs classes that had many init=False fields.

Now, though, with the new versions of cattrs (v23.2.0), this behavior changed, breaking my code.

I'd like to be able to enable the old behavior back globally on a converter, instead of having to enable it for every single class, as I have many classes all over the place that would benefit from re-enabling init=False fields in conversion.

import attrs
import cattrs


@attrs.define
class Foo:
    bar: int
    baz: str = attrs.field(init=False)


foo = Foo(bar=1)
foo.baz = "hello"


converter = cattrs.Converter()
print(converter.unstructure(foo))
# before: {'bar': 1, 'baz': 'hello'}
# after: {'bar': 1}

I thought about something like this:

import cattrs
from cattrs.strategies import include_init_false

converter = cattrs.Converter()
include_init_false(converter)

# OR

converter = cattrs.Converter(include_init_false=True)
Vorherrschende Sprache
Python
Sterne
1.1k
Forks
165
Ø Merge
11 Std. 51 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python-attrs/cattrs

Alle Issues in python-attrs/cattrs

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.