CodeSampleX

Sample

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

Verified sample for pypi attrs 26.1.0: Author custom validators, converters, default factories, and custom serializers in attrs without falling into…

sha256:04534868bcf83a1c9437d56575f5b38eea5b61ac3a126103d53fa34f2fbd7310

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment python 3.12 linux x64 python 3.12 python pip

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift
Packages
Symbols
  • 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
Environment
python 3.12
Created
2026-08-17T03:18:45Z

Contract

  1. assert custom @field.validator methods require (self, attribute, value) and fail with TypeError when defined with (self, value)
  2. assert validator return values are discarded and do not mutate the attribute value
  3. assert @username.validator on top of field(validator=[...]) chains all checks in sequence via _AndValidator
  4. assert validators.matches_re uses anchored re.match by default and rejects non-prefix matches
  5. assert validators.in_(Enum) follows Python 3.12 Enum membership: raw member values are accepted without conversion while absent values raise ValueError
  6. assert validators.not_ raises ValueError when the inner validator does not raise
  7. assert validators.deep_iterable and deep_mapping validate container types and all child items or key-value pairs
  8. 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
  9. assert @field.converter does not exist on _CountingAttr and raises TypeError at class definition because field().converter is None
  10. assert converter=int with default=None crashes on __init__ with TypeError because converters execute on default values, requiring converters.optional(int)
  11. assert converters.pipe with default_if_none and to_bool chains fallback replacement and boolean conversion
  12. assert attrs.Converter(takes_self=True, takes_field=True) allows converters to receive (value, self, field) while raw 2-arg callables fail with TypeError
  13. assert on_setattr custom setters execute only on attribute assignment and never during __init__
  14. assert attrs permits default=[] without error at class definition, silently creating shared mutable state across instances
  15. assert Factory(takes_self=True) and @field.default compute dynamic defaults from self during initialization
  16. assert passing both default= and factory= to attrs.field raises ValueError
  17. assert attrs.asdict keys by attribute.name and not attribute.alias, causing Class(**attrs.asdict(obj)) to fail with TypeError on aliased fields
  18. assert attrs.asdict filter takes (attribute, value) -> bool and filters.exclude removes matching attributes
  19. assert attrs.asdict value_serializer requires (inst, field, value) and fails with TypeError on 2-arg callables
  20. assert attrs.evolve keys by alias and re-runs validators on new instances
  21. assert attrs.cmp_using customizes equality and ordering when order=True is set on class and field has both eq and order defined
  22. assert mandatory fields defined in a subclass after parent default fields raise ValueError at definition unless kw_only=True is specified

Files

  • NOTES.md
  • csx.json
  • requirements.txt
  • src/__init__.py
  • src/models.py
  • test/contract.py

Download the source artifact (tar.gz)

Origin Seeder

csx-seed