Title: Iterating over ChainMap.values() and ChainMap.items() updates underlying defaultdicts · Issue #93432 · python/cpython · GitHub
Open Graph Title: Iterating over ChainMap.values() and ChainMap.items() updates underlying defaultdicts · Issue #93432 · python/cpython
X Title: Iterating over ChainMap.values() and ChainMap.items() updates underlying defaultdicts · Issue #93432 · python/cpython
Description: Bug report Hello, I encountered some confusing behavior when combining ChainMap with defaultdicts. Might be related to #23534 Specifically, iterating over the values or items of the ChainMap updates one of the underlying dictionaries, an...
Open Graph Description: Bug report Hello, I encountered some confusing behavior when combining ChainMap with defaultdicts. Might be related to #23534 Specifically, iterating over the values or items of the ChainMap update...
X Description: Bug report Hello, I encountered some confusing behavior when combining ChainMap with defaultdicts. Might be related to #23534 Specifically, iterating over the values or items of the ChainMap update...
Opengraph URL: https://github.com/python/cpython/issues/93432
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Iterating over ChainMap.values() and ChainMap.items() updates underlying defaultdicts","articleBody":"**Bug report**\r\n\r\nHello,\r\nI encountered some confusing behavior when combining ChainMap with defaultdicts. Might be related to #23534\r\nSpecifically, iterating over the values or items of the ChainMap updates one of the underlying dictionaries, and returns the wrong result. \r\nJust iterating over they keys or the dictionary directly produces the right results still and doesn't update the underlying dictionaries. \r\n\r\n```\r\nfrom collections import ChainMap, defaultdict\r\n\r\nd1 = defaultdict(int, {'a': 1, 'b': 2})\r\nd2 = defaultdict(int, {'c': 3, 'd': 4})\r\nd3 = ChainMap(d1, d2)\r\n\r\nprint('Prior to iter')\r\nprint(d1)\r\nprint(d2)\r\nprint('After iter')\r\na = list(d3.values()) # Same result when calling d3.items\r\nprint(a) # Should return: [1, 2, 3, 4]. Returns: [0, 0, 1, 2]\r\nprint(d1) # Now: {'a': 1, 'b': 2, 'c': 0, 'd': 0}\r\nprint(d2) # Unchanged\r\n```\r\n\r\n**Your environment**\r\n\r\nTested on Python version 3.10.4. \r\nLinux 5.13.0-41-generic #46~20.04.1-Ubuntu SMP \r\nx86_64 x86_64 x86_64 GNU/Linux\r\n","author":{"url":"https://github.com/Alexamk","@type":"Person","name":"Alexamk"},"datePublished":"2022-06-02T09:10:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/93432/cpython/issues/93432"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a1e1dcad-dfa5-3d6a-c1b9-0306b41a79e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D0F8:2D943D:3D311B:55C60D:696A0B0B |
| html-safe-nonce | 8c4ead80266b12c6d6402af0baf807e4f0e61f4baef966ee023360e5b986248f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEY4OjJEOTQzRDozRDMxMUI6NTVDNjBEOjY5NkEwQjBCIiwidmlzaXRvcl9pZCI6IjQ5MjU1MTE4MjAxNTY0NzIwNzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d72ffe2a9985f9ed63cbdb72cff5fd715ea1e433fc89abe2acc4caf36a552ed5 |
| hovercard-subject-tag | issue:1257912364 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/93432/issue_layout |
| twitter:image | https://opengraph.githubassets.com/94dab44da55714260cacdb437deabf710c73bea6b2f665be204e6302d62abfba/python/cpython/issues/93432 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/94dab44da55714260cacdb437deabf710c73bea6b2f665be204e6302d62abfba/python/cpython/issues/93432 |
| og:image:alt | Bug report Hello, I encountered some confusing behavior when combining ChainMap with defaultdicts. Might be related to #23534 Specifically, iterating over the values or items of the ChainMap update... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Alexamk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width