CodeSampleX

샘플

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 illusions…

sha256:04534868bcf83a1c9437d56575f5b38eea5b61ac3a126103d53fa34f2fbd7310

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

csx-seed