CodeSampleX

샘플

attrs 26.1.0: Decide whether attrs still buys anything over dataclasses on modern Python, and what changes in each direction

검증된 샘플 — pypi attrs 26.1.0: Decide whether attrs still buys anything over dataclasses on modern Python, and what changes in each direction. python 3.12 …

sha256:db459e2a5619e5bc96877e0fc6aefd6229be3342cc28685624eacd9e170bf4b7

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 python 3.12 linux x64 python 3.12 python pip

검증 실행 환경

환경 컨트랙트 단계 실행일
python 3.12 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pypi@1
2026-08-14
python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · pypi@1
2026-08-18

케이스

MIGRATION
목표
Decide whether attrs still buys anything over dataclasses on modern Python, and what changes in each direction
패키지
심벌
  • attrs.define
  • attrs.field
  • attrs.frozen
  • attrs.evolve
  • attrs.validators.instance_of
  • attrs.validators.disabled
  • attrs.setters.NO_OP
  • attrs.asdict
  • attrs.exceptions.FrozenInstanceError
  • attr.s
  • dataclasses.dataclass
  • dataclasses.replace
  • dataclasses.FrozenInstanceError
환경
python 3.12
생성일
2026-08-14T12:07:55Z

컨트랙트

  1. assert neither library enforces an annotation: a dataclass stores a str in an int field and so does an @define class with no validator
  2. assert an attrs validator runs at __init__, with instance_of raising TypeError and gt raising ValueError, and that ge, lt and le raise ValueError too
  3. assert the converter runs before the validator, so converter=int and instance_of(int) coexist and "9000" is stored as 9000
  4. assert @define runs converter and validator again on assignment, where the dataclass keeps whatever was assigned
  5. assert __post_init__ is not the equivalent hook: it runs at __init__ and again through dataclasses.replace, and never on assignment
  6. assert on_setattr=NO_OP keeps the __init__ conversion and drops the assignment one, so the field holds either type
  7. assert attrs.validators.disabled() switches off the validators of every class in the process, so a validator is not a boundary
  8. assert @define is slotted, so an undeclared attribute raises AttributeError and has no __dict__, while the dataclass accepts it
  9. assert @dataclass(slots=True) exists and that both decorators return a new class object, not the one that was decorated
  10. assert attrs puts __weakref__ in __slots__ and @dataclass(slots=True) does not, so weakref.ref works on the attrs class and raises TypeError on the dataclass
  11. assert the slotted dataclass breaks zero-argument super() on Python 3.12 with TypeError, and attrs' slotted subclass with the same body does not
  12. assert the cause is the __class__ closure cell, which attrs rebinds to the class it returns and the stdlib leaves on the discarded original, and that super(Child, self) works around it
  13. assert attrs' FrozenInstanceError reports module attr.exceptions and is a different class from dataclasses.FrozenInstanceError, with neither a subclass of the other
  14. assert catching dataclasses.FrozenInstanceError does not catch the attrs error and catching the attrs error does not catch the dataclass one
  15. assert both frozen errors subclass AttributeError, the narrowest single except clause that covers both
  16. assert a mandatory field after a defaulted one is refused at class definition by both, ValueError from attrs and TypeError from dataclasses
  17. assert kw_only=True lifts that rule in both libraries
  18. assert an attrs field named _token takes the init keyword token and refuses _token, while the dataclass field does the reverse
  19. assert attrs.evolve keys on the init parameter name and re-runs the validator, while dataclasses.replace keys on the field name and runs no validator of its own
  20. assert an init=False field is refused by replace with ValueError naming the field and by evolve with TypeError for an unknown keyword
  21. assert the libraries do not recognise each other: is_dataclass and attrs.has are False, dataclasses.fields raises TypeError and attrs.fields raises NotAnAttrsClassError
  22. assert a fresh interpreter run under -W error imports attr with no warning at all, and attr.__version__ matches the installed attrs
  23. assert the namespaces moved one way only: define, field, frozen, evolve and fields are the same objects on attr and attrs, while s, ib, attrib and attributes exist only on attr
  24. assert a shared name is not always a shared object: attr.asdict is not attrs.asdict and only the old one takes retain_collection_types, and attr.exceptions is not attrs.exceptions
  25. assert an @attr.s class is unslotted and converts at __init__ only, leaving object.__setattr__ in place where @define installs its own

파일

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

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

오리진 시더

anonymous