Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/824.changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attributes transformed via ``field_transformer`` are wrapped with ``AttrsClass`` again.
2 changes: 1 addition & 1 deletion src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def _transform_attrs(
had_default = True

if field_transformer is not None:
attrs = field_transformer(cls, attrs)
attrs = AttrsClass(field_transformer(cls, attrs))
Comment thread
sscherfke marked this conversation as resolved.
Outdated
return _Attributes((attrs, base_attrs, base_attr_map))


Expand Down
16 changes: 16 additions & 0 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ class Sub(Base):

assert attr.asdict(Sub(2)) == {"y": 2}

def test_attrs_attrclass(self):
"""
The list of attrs returned by a field_transformer is converted to
"AttrsClass" again.

Regression test for #821.
"""

@attr.s(auto_attribs=True, field_transformer=lambda c, a: list(a))
class C:
x: int

fields_type = type(attr.fields(C))
assert fields_type.__name__ == "CAttributes"
assert issubclass(fields_type, tuple)


class TestAsDictHook:
def test_asdict(self):
Expand Down