Latest Results
fix: recurse into collections nested inside collections in astuple()
`attrs.astuple()` and `attr.astuple()` only converted *attrs* instances that
were nested at most one collection deep: an instance inside a list inside a
list, inside a tuple inside a list, or inside a list used as a mapping value
was returned as-is. `attrs.asdict()` converts all of them.
`astuple()` looked at the elements of a collection but never recursed into
nested collections themselves, while `asdict()` routes every value through
`_asdict_anything()`.
Add `_astuple_anything()` -- mirroring `_asdict_anything()` -- and use it for
collection items and mapping keys and values, so that nested collections are
rebuilt according to *retain_collection_types*, *tuple_factory* is applied to
instances found at any depth and *filter* is honored everywhere.
Nested mappings are rebuilt from an intermediate dict, so subclasses like
`OrderedDict` and `Counter` are reconstructed correctly; mappings whose
constructor can't take a mapping object -- for example `defaultdict` -- fall
back to a plain dict, just like `asdict()` does.
Since mapping keys and values are now converted with the recursive helper,
*filter* is also applied to *attrs* instances used as dictionary keys and
values, consistently with sequences.
Tests: `tests/test_funcs.py::TestAsTuple::test_nested_*` cover nested lists,
tuples, mappings, namedtuples, mappings that can't be rebuilt, container keys
and non-atomic values. They fail on the unfixed source.
Signed-off-by: simpleqt <2015900818@qq.com>simpleqt:fix-astuple-nested-collections Latest Branches
-68%
simpleqt:fix-astuple-nested-collections 0%
Johnny-Kao:perf/astuple-dict-atomic 0%
emadleo13:fix-1637-user-defined-slots © 2026 CodSpeed Technology