Skip to content

dataclasses.astuple breaks on DefaultDict #98169

Description

@kwsp

Bug report

This is very similar to #79721

from dataclasses import dataclass, astuple
from typing import DefaultDict, List
from collections import defaultdict

@dataclass
class C:
    mp: DefaultDict[str, List]

dd = defaultdict(list)
dd["x"].append(12)
c = C(mp=dd)
d = astuple(c)  # throws "TypeError: first argument must be callable or None"


assert d == ({"x": [12]},)
assert d[0] is not c.mp  # make sure defaultdict is copied

Basically applying the same fix for asdict from #32056 to astuple.

Your environment

  • CPython versions tested on: 3.10.7
  • Operating system and architecture: macOS, arm64

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 11, 2022
  2. added a commit that references this issue on Oct 11, 2022
  3. added a commit that references this issue on Mar 13, 2023
  4. added a commit that references this issue on Mar 14, 2023
  5. added a commit that references this issue on Mar 27, 2023
  6. added a commit that references this issue on Apr 11, 2023
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-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions