镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Closed

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

Activity

  1. added a commit that references this issue on Oct 19, 2020
    a8774a7
  2. added a commit that references this issue on Oct 19, 2020
    0e6c74a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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