Exemple
attrs 26.1.0: Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift
Échantillon vérifié pour pypi attrs 26.1.0: Author custom validators, converters, default factories, and custom serializers in attrs without falling into…
sha256:04534868bcf83a1c9437d56575f5b38eea5b61ac3a126103d53fa34f2fbd7310
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 2
Environnement déclaré
python 3.12 linux x64 python 3.12 python pip
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
Cas
HOW- Objectif
- Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift
- Paquets
- Symboles
-
- attrs.define
- attrs.field
- attrs.validators
- attrs.validators.instance_of
- attrs.validators.optional
- attrs.validators.and_
- attrs.validators.or_
- attrs.validators.not_
- attrs.validators.matches_re
- attrs.validators.in_
- attrs.validators.min_len
- attrs.validators.max_len
- attrs.validators.deep_iterable
- attrs.validators.deep_mapping
- attrs.converters.optional
- attrs.converters.default_if_none
- attrs.converters.pipe
- attrs.converters.to_bool
- attrs.Converter
- attrs.Factory
- attrs.setters
- attrs.filters.include
- attrs.filters.exclude
- attrs.cmp_using
- attrs.asdict
- attrs.evolve
- Environnement
- python 3.12
- Créé
- 2026-08-17T03:18:45Z
Contrat
- assert custom @field.validator methods require (self, attribute, value) and fail with TypeError when defined with (self, value)
- assert validator return values are discarded and do not mutate the attribute value
- assert @username.validator on top of field(validator=[...]) chains all checks in sequence via _AndValidator
- assert validators.matches_re uses anchored re.match by default and rejects non-prefix matches
- assert validators.in_(Enum) follows Python 3.12 Enum membership: raw member values are accepted without conversion while absent values raise ValueError
- assert validators.not_ raises ValueError when the inner validator does not raise
- assert validators.deep_iterable and deep_mapping validate container types and all child items or key-value pairs
- assert validator=[optional(instance_of(int)), gt(0)] fails on None with TypeError because gt(0) still runs on None, while optional(and_(...)) protects the composite
- assert @field.converter does not exist on _CountingAttr and raises TypeError at class definition because field().converter is None
- assert converter=int with default=None crashes on __init__ with TypeError because converters execute on default values, requiring converters.optional(int)
- assert converters.pipe with default_if_none and to_bool chains fallback replacement and boolean conversion
- assert attrs.Converter(takes_self=True, takes_field=True) allows converters to receive (value, self, field) while raw 2-arg callables fail with TypeError
- assert on_setattr custom setters execute only on attribute assignment and never during __init__
- assert attrs permits default=[] without error at class definition, silently creating shared mutable state across instances
- assert Factory(takes_self=True) and @field.default compute dynamic defaults from self during initialization
- assert passing both default= and factory= to attrs.field raises ValueError
- assert attrs.asdict keys by attribute.name and not attribute.alias, causing Class(**attrs.asdict(obj)) to fail with TypeError on aliased fields
- assert attrs.asdict filter takes (attribute, value) -> bool and filters.exclude removes matching attributes
- assert attrs.asdict value_serializer requires (inst, field, value) and fails with TypeError on 2-arg callables
- assert attrs.evolve keys by alias and re-runs validators on new instances
- assert attrs.cmp_using customizes equality and ordering when order=True is set on class and field has both eq and order defined
- assert mandatory fields defined in a subclass after parent default fields raise ValueError at definition unless kw_only=True is specified
Fichiers
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/models.py
- test/contract.py