Sample
Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift
sha256:04534868bcf83a1c9437d56575f5b38eea5b61ac3a126103d53fa34f2fbd7310
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Case
- Goal
- Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift HOW
- Packages
- attrs 26.1.0
- Environment
- python 3.12
- Created
- 2026-08-17T03:18:45Z
Contract
- 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
Files
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/models.py
- test/contract.py
Download the verified artifact (tar.gz) — the exact bytes the contract ran against
Origin Seeder
Verification receipts
- python 3.12 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · python@1 · 2026-08-17 · ed25519:d91480838ac982c9