Skip to content

attr.asdict -> attrs.asdict regression for sets of instances #1180

@jgarvin

Description

@jgarvin

Hard coding retain_collection_types=True in attrs.asdict means that you can no longer convert objects that contain sets of other objects. Reproducer:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import attr
import attrs
from attrs import frozen

@frozen
class Foo:
    x: int

@frozen
class Bar:
    foos: set[Foo]

# works!
print(attr.asdict(Bar({Foo(3)})))

# fails with:
# Traceback (most recent call last):
#   File "/tmp/regression.py", line 16, in <module>
#     print(attrs.asdict(Bar({Foo(3)})))
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/home/x/.local/lib/python3.11/site-packages/attr/_next_gen.py", line 214, in asdict
#     return _asdict(
#            ^^^^^^^^
#   File "/home/x/.local/lib/python3.11/site-packages/attr/_funcs.py", line 75, in asdict
#     rv[a.name] = cf(
#                  ^^^
# TypeError: unhashable type: 'dict'
print(attrs.asdict(Bar({Foo(3)})))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions