Skip to content

attr.asdict(retain_collection_types=False) doesn't support frozenset #657

@kanetkarster

Description

@kanetkarster

Hey, I ran into some surprising behavior when using attr.asdict() with a frozen set.
I was expecting retain_collection_types=False to convert a frozenset to a list, as it does with a tuple or list, but it keeps it as a frozenset

Example

import attr

@attr.s
class Foo:
    bar = attr.ib()

DATA = (1, 2, 3)
print("set:", attr.asdict(Foo(set(DATA))))
print("frozenset", attr.asdict(Foo(frozenset(DATA))))

Output:

$ python attr_demo.py
set: {'bar': [1, 2, 3]}
frozenset {'bar': frozenset({1, 2, 3})}

Expected Output

$ python attr_demo.py
set: {'bar': [1, 2, 3]}
frozenset  {'bar': [1, 2, 3]}

it looks like the code change is adding frozenset to the isinstance check on https://github.com/python-attrs/attrs/blob/master/src/attr/_funcs.py#L55

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions