"attrs-order-check-after-transformer"
# field checks done too early causing error
(python-attrs/attrs issue #1147, verbatim body)
Attrs does some checks on fields like no defaulted fields coming before non-defaulted fields before running custom field transformers. This is a problem when a field transformer intends to modify the fields but gets an error before being able to apply their modification.
For example, this field transformer reorders fields so that in fact the defaulted field `x` comes after the non-defaulted field `y`. But attrs errors before the transformer is ever called.
```python
def order_by_metadata(cls, fields):
fields.sort(key=lambda x: x.metadata["field_order"])
return fields
@define(field_transformer=order_by_metadata)
class A:
x: int = field(metadata={"field_order": 1}, default=0)
y: int = field(metadata={"field_order": 0})
```
```
Traceback (most recent call last):
File "...", line 426, in <module>
class A:
File ".../attr/_next_gen.py", line 146, in wrap
return do_it(cls, True)
File ".../attr/_next_gen.py", line 90, in do_it
return attrs(
File ".../attr/_make.py", line 1603, in attrs
return wrap(maybe_cls)
File ".../attr/_make.py", line 1499, in wrap
builder = _ClassBuilder(
File ".../attr/_make.py", line 657, in __init__
attrs, base_attrs, base_map = _transform_attrs(
File ".../attr/_make.py", line 566, in _transform_attrs
raise ValueError(
ValueError: No mandatory attributes allowed after an attribute with a default value or factory. Attribute in question: Attribute(name='y', default=NOTHING, validator=None, repr=True, eq=True, eq_key=None, order=True, order_key=None, hash=None, init=True, metadata=mappingproxy({'field_order': 0}), type='int', converter=None, kw_only=False, inherited=False, on_setattr=None, alias=None)
```
I think these checks should be done after custom field transformers.
Every requirement marked done on this page was demonstrated able to FAIL before it was made to pass.
1 requirement · 1 done and proved · 0 holding up the handover
DONE — AND PROVED# field checks done too early causing error (python-attrs/attrs issue #1147, verbatim body) Attrs does some checks on fields like no defaulted fields coming before non-defaulted fields before running custom field transformers. This is a problem when a field transformer intends to modify the fields b
The repository had no check for this. Wringer wrote one before the work began, recorded it failing then, and the same check passes now.
It was red first. The repository had no check for this. Wringer wrote one before the work began, recorded it failing then, and the same check passes now.
What this page does not claim — Wringer's own words, unedited
- Evidenced means the bound gate passed and has demonstrably failed before. It does not mean the criterion is what the user needed, that the gate covers the criterion's whole meaning, or that coverage cannot narrow later — `wring health` watches that across time.
- The gate-to-criterion binding is a human's declaration. Wringer checks the binding's consequences, never its wisdom.
- Human criteria are answered by people. Nothing here scored them.
- A sensitivity receipt says the gate's result differed between the two trees, not that the difference was the change. A gate whose own command arrived with the change reads sensitive for that reason alone — the citation beside it is how you tell.
- A witness proves the stated criterion could fail and was made to pass. It does not certify agreement with an unstated intended fix, and where the criterion under-describes the intent the witness inherits that gap. Nothing here catches a change that satisfies the criterion and is still wrong.
- A witness evidences ONE criterion. A manufactured fail-to-pass check is necessary and demonstrably not sufficient — it raises the floor and does not make a delivery safe.
- The pin is tamper-EVIDENT, not tamper-proof: a worker on the host can read and rewrite what it finds there. It becomes a boundary only under run.containment.
For engineers
- acceptance record:
wringer.acceptance.v2 - verifications in this loop: 1