Title: gh-132762: Fix underallocation bug in dict.fromkeys() and expand test coverage by angela-tarantula · Pull Request #133627 · python/cpython · GitHub
Open Graph Title: gh-132762: Fix underallocation bug in dict.fromkeys() and expand test coverage by angela-tarantula · Pull Request #133627 · python/cpython
X Title: gh-132762: Fix underallocation bug in dict.fromkeys() and expand test coverage by angela-tarantula · Pull Request #133627 · python/cpython
Description: Closes #132762 Summary dict_set_fromkeys() was only sizing its new table by the size of the iterable input, ignoring any existing entries in the dictionary. This triggered an infinite loop in dictresize() whenever the new dictionary size was too small to reinsert those entries. This patch adds the same Py_MAX(…, DK_LOG_SIZE(mp->ma_keys)) guard that dict_dict_fromkeys() uses, so we never accidentally shrink the table below its current capacity. The relevant test case baddict3 has been updated to cover this edge case. For more background, see my proposal. 3 New Regression Tests Ever since the fast path was updated, the slow path completely lost test coverage. To rectify this, I added 3 new tests: 1 slow-path test when the iterable input is neither a set nor a dictionary 1 slow-path test when fromkeys() is called on a proper subclass of dict, baddict4 1 fast-path test when the input is a set (worth testing explicitly now that dict_dict_fromkeys() and dict_set_fromkeys() are separate) Thanks for the review! @DinoV @colesbury Issue: gh-132762
Open Graph Description: Closes #132762 Summary dict_set_fromkeys() was only sizing its new table by the size of the iterable input, ignoring any existing entries in the dictionary. This triggered an infinite loop in dictr...
X Description: Closes #132762 Summary dict_set_fromkeys() was only sizing its new table by the size of the iterable input, ignoring any existing entries in the dictionary. This triggered an infinite loop in dictr...
Opengraph URL: https://github.com/python/cpython/pull/133627
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4cd29237-4243-ad29-5e98-5d950e156153 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B4BE:23AA91:137444:1A0750:6A53FA12 |
| html-safe-nonce | ca9c0a6e3079da119e9082485440d23a7ce3799dbfa01a4a519c2cd74e7cebc1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNEJFOjIzQUE5MToxMzc0NDQ6MUEwNzUwOjZBNTNGQTEyIiwidmlzaXRvcl9pZCI6IjcwNzA4MDU4NjgwNzQ0OTg1NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9ed106df4605ff19dffd1a3fcef6b83b28d59dc30930c3479da79917331f9fe7 |
| hovercard-subject-tag | pull_request:2505755184 |
| 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/133627/files |
| twitter:image | https://avatars.githubusercontent.com/u/59097311?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/59097311?s=400&v=4 |
| og:image:alt | Closes #132762 Summary dict_set_fromkeys() was only sizing its new table by the size of the iterable input, ignoring any existing entries in the dictionary. This triggered an infinite loop in dictr... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width