サンプル
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
検証済みサンプル — pypi attrs 26.1.0: Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator…
sha256:04534868bcf83a1c9437d56575f5b38eea5b61ac3a126103d53fa34f2fbd7310
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 2
宣言された環境
python 3.12 linux x64 python 3.12 python pip
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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 |
ケース
HOW- ゴール
- Author custom validators, converters, default factories, and custom serializers in attrs without falling into decorator illusions, signature mismatches, or serialization key drift
- パッケージ
- シンボル
-
- 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
- 環境
- python 3.12
- 作成日
- 2026-08-17T03:18:45Z
コントラクト
- 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
ファイル
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/models.py
- test/contract.py