Title: bpo-35540 dataclasses.asdict support defaultdict fields by kwsp · Pull Request #32056 · python/cpython · GitHub
Open Graph Title: bpo-35540 dataclasses.asdict support defaultdict fields by kwsp · Pull Request #32056 · python/cpython
X Title: bpo-35540 dataclasses.asdict support defaultdict fields by kwsp · Pull Request #32056 · python/cpython
Description: https://bugs.python.org/issue35540 dataclasses.asdict breaks when there are defaultdicts in the dataclass attributes because it assumes defaultdict and dict are the same thing, but in reality defaultdict takes a default_factory as the first argument in its constructor. Since dataclasses.asdict already supports NamedTuples, I think its fair that defaultdict, which is also in the standard library, does not break dataclasses. Test: from dataclasses import dataclass, asdict 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 = asdict(c) # throws "TypeError: first argument must be callable or None" assert d == {"mp": {"x": [12]}} https://bugs.python.org/issue35540
Open Graph Description: https://bugs.python.org/issue35540 dataclasses.asdict breaks when there are defaultdicts in the dataclass attributes because it assumes defaultdict and dict are the same thing, but in reality defau...
X Description: https://bugs.python.org/issue35540 dataclasses.asdict breaks when there are defaultdicts in the dataclass attributes because it assumes defaultdict and dict are the same thing, but in reality defau...
Opengraph URL: https://github.com/python/cpython/pull/32056
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:78aabce0-2542-9468-67f3-543f754173e6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A088:739BE:64EB4:88504:6969CB23 |
| html-safe-nonce | 1045b26cb428bfdb80e8d64b8a837544730257f0373f29eec4a134a0ae7e55f6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDg4OjczOUJFOjY0RUI0Ojg4NTA0OjY5NjlDQjIzIiwidmlzaXRvcl9pZCI6IjMyNjkzNzYxOTc1MDUxNzQzMDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | cc8ad1d0281891f59f28dd336df08226a4ed76b22e7844bbdc49da3f55d6b794 |
| hovercard-subject-tag | pull_request:886366057 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/32056/files |
| twitter:image | https://avatars.githubusercontent.com/u/30088608?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/30088608?s=400&v=4 |
| og:image:alt | https://bugs.python.org/issue35540 dataclasses.asdict breaks when there are defaultdicts in the dataclass attributes because it assumes defaultdict and dict are the same thing, but in reality defau... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width