René's URL Explorer Experiment


Title: dict.fromkeys() re-hashes keys taken from a set, frozenset, or dict · Issue #8490 · RustPython/RustPython · GitHub

Open Graph Title: dict.fromkeys() re-hashes keys taken from a set, frozenset, or dict · Issue #8490 · RustPython/RustPython

X Title: dict.fromkeys() re-hashes keys taken from a set, frozenset, or dict · Issue #8490 · RustPython/RustPython

Description: Summary dict.fromkeys() recomputes __hash__ for every key when the iterable is a set, frozenset, or dict — all of which already store a hash per entry. CPython's dict_fromkeys_impl (Objects/dictobject.c) branches on PyAnySet_Check / PyDi...

Open Graph Description: Summary dict.fromkeys() recomputes __hash__ for every key when the iterable is a set, frozenset, or dict — all of which already store a hash per entry. CPython's dict_fromkeys_impl (Objects/dictobj...

X Description: Summary dict.fromkeys() recomputes __hash__ for every key when the iterable is a set, frozenset, or dict — all of which already store a hash per entry. CPython's dict_fromkeys_impl (Objects/dic...

Opengraph URL: https://github.com/RustPython/RustPython/issues/8490

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"dict.fromkeys() re-hashes keys taken from a set, frozenset, or dict","articleBody":"## Summary\n\n`dict.fromkeys()` recomputes `__hash__` for every key when the iterable is a `set`, `frozenset`, or `dict` — all of which already store a hash per entry. CPython's `dict_fromkeys_impl` (`Objects/dictobject.c`) branches on `PyAnySet_Check` / `PyDict_CheckExact` and feeds the hash from `_PySet_NextEntry` / `_PyDict_Next` straight into `insertdict`.\n\nThis is the dict-target counterpart of #8489 (set/frozenset target).\n\n## Reproduction\n\n```python\nclass HashCountingInt(int):\n    def __init__(self, *args):\n        self.hash_count = 0\n    def __hash__(self):\n        self.hash_count += 1\n        return int.__hash__(self)\n\nd = dict.fromkeys(map(HashCountingInt, range(10)))\nprint(sum(e.hash_count for e in d))   # 10\ndict.fromkeys(set(d))\nprint(sum(e.hash_count for e in d))   # CPython: 10, RustPython: 20\n```\n\n`Lib/test/test_set.py:333` — `TestJointOps.test_do_not_rehash_dict_keys` asserts on both directions, so its `@unittest.expectedFailure  # TODO: RUSTPYTHON` marker can only be dropped once both this issue and #8489 are done. It is inherited by `TestSet`, `TestSetSubclass`, `TestFrozenSet` and `TestFrozenSetSubclass` (4 of the 10 expected failures in `test_set.py`).\n\n## Analysis\n\n`PyDict::fromkeys` (`crates/vm/src/builtins/dict.rs:377`) iterates generically regardless of what the source is:\n\n```rust\nmatch d.downcast_exact::\u003cSelf>(vm) {\n    Ok(pydict) => {\n        for key in iterable.iter(vm)? {\n            pydict.__setitem__(key?, value.clone(), vm)?;\n        }\n        Ok(pydict.into_pyref().into())\n    }\n    ...\n}\n```\n\n`__setitem__` → `inner_setitem` (`:302`) → `entries.insert()` ends up calling `key.key_hash(vm)`, so a source that already knows the hash pays for it twice.\n","author":{"url":"https://github.com/fregataa","@type":"Person","name":"fregataa"},"datePublished":"2026-08-11T01:09:33Z","url":"https://github.com/RustPython/RustPython/issues/8490"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:31aeae93-d008-9bd1-5d3b-0713dc72db76
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE1B2:39FDE1:5C4BA5:73FAF0:6B0206B3
html-safe-nonced3736ba47338b66962c3375c50cf6a7e905d0e7603b2b0d2aeb3bffbe45a6f78
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUIyOjM5RkRFMTo1QzRCQTU6NzNGQUYwOjZCMDIwNkIzIiwidmlzaXRvcl9pZCI6IjQ0MzcwMzYyMTc0MjI0NDgzMDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8ba7c871a9ececb3a3110984a8b9ffd28bb4c06a32cbcf7f39f6c4e9b8de0454
hovercard-subject-tagissue:5115707621
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/RustPython/RustPython/8490/issue_layout
twitter:imagehttps://opengraph.githubassets.com/360aa59f34e4235f367796524e79a5ba41afb10bb46455b31aedf2d8272d3d4e/RustPython/RustPython/issues/8490
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/360aa59f34e4235f367796524e79a5ba41afb10bb46455b31aedf2d8272d3d4e/RustPython/RustPython/issues/8490
og:image:altSummary dict.fromkeys() recomputes __hash__ for every key when the iterable is a set, frozenset, or dict — all of which already store a hash per entry. CPython's dict_fromkeys_impl (Objects/dictobj...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamefregataa
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/RustPython/RustPython/issues/8490#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F8490
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F8490
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/issues/8490
Reloadhttps://github.com/RustPython/RustPython/issues/8490
Reloadhttps://github.com/RustPython/RustPython/issues/8490
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests133 (133)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
https://github.com/RustPython/RustPython
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8490
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8490
#8503https://github.com/RustPython/RustPython/pull/8503
dict.fromkeys() re-hashes keys taken from a set, frozenset, or dicthttps://github.com/RustPython/RustPython/issues/8490#top
#8503https://github.com/RustPython/RustPython/pull/8503
z-ca-2026Tag to track Contribution Academy 2026https://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22z-ca-2026%22
https://github.com/fregataa
fregataahttps://github.com/fregataa
on Aug 11, 2026https://github.com/RustPython/RustPython/issues/8490#issue-5115707621
#8489https://github.com/RustPython/RustPython/issues/8489
#8489https://github.com/RustPython/RustPython/issues/8489
fregataahttps://github.com/fregataa
on Aug 11, 2026https://github.com/RustPython/RustPython/issues/8490#event-29278154626
Reuse stored hashes when building a set from a set/frozenset/dicthttps://github.com/fregataa/RustPython/commit/2924f86ff184e5b28eb684d1e32237f318f4b537
2924f86https://github.com/fregataa/RustPython/commit/2924f86ff184e5b28eb684d1e32237f318f4b537
youknowonehttps://github.com/youknowone
z-ca-2026Tag to track Contribution Academy 2026https://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22z-ca-2026%22
on Aug 11, 2026https://github.com/RustPython/RustPython/issues/8490#event-29281152866
youknowonehttps://github.com/youknowone
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8490#event-29324866325
Reuse stored hashes when building a set from a set/frozenset/dict (#8491https://github.com/RustPython/RustPython/commit/7612e68357e4d7b8c386eb7785d000f5fcfe6f8d
#8491https://github.com/RustPython/RustPython/pull/8491
7612e68https://github.com/RustPython/RustPython/commit/7612e68357e4d7b8c386eb7785d000f5fcfe6f8d
fregataahttps://github.com/fregataa
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8490#event-29342180220
Reuse stored hashes in dict.fromkeys()https://github.com/fregataa/RustPython/commit/324ecaa59b399e90be903f2cb04af9606837e3a5
https://docs.github.com/articles/closing-issues-via-commit-messages
324ecaahttps://github.com/fregataa/RustPython/commit/324ecaa59b399e90be903f2cb04af9606837e3a5
youknowonehttps://github.com/youknowone
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8490#event-29361738272
Reuse stored hashes in dict.fromkeys() (#8503)https://github.com/RustPython/RustPython/commit/db5de5e5e238f8b0e03b2cff17f8603bbf45ef84
#8503https://github.com/RustPython/RustPython/pull/8503
https://docs.github.com/articles/closing-issues-via-commit-messages
db5de5ehttps://github.com/RustPython/RustPython/commit/db5de5e5e238f8b0e03b2cff17f8603bbf45ef84
youknowonehttps://github.com/youknowone
completedhttps://github.com/RustPython/RustPython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#8503https://github.com/RustPython/RustPython/pull/8503
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8490#event-29361738332
youknowonehttps://github.com/youknowone
on Sep 16, 2026https://github.com/RustPython/RustPython/issues/8490#event-31263100020
Reuse stored hashes when building a set from a set/frozenset/dict (#8491https://github.com/RustPython/RustPython/commit/856c3da0beacb47c34a1fcf19b9cffb86988749f
#8491https://github.com/RustPython/RustPython/pull/8491
856c3dahttps://github.com/RustPython/RustPython/commit/856c3da0beacb47c34a1fcf19b9cffb86988749f
Reuse stored hashes in dict.fromkeys() (#8503)https://github.com/RustPython/RustPython/commit/7e6eaa8e3cf2eba6a825c1fe378368e7977361f4
#8503https://github.com/RustPython/RustPython/pull/8503
7e6eaa8https://github.com/RustPython/RustPython/commit/7e6eaa8e3cf2eba6a825c1fe378368e7977361f4
Sign up for freehttps://github.com/signup?return_to=https://github.com/RustPython/RustPython/issues/8490
Sign in to commenthttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8490
z-ca-2026Tag to track Contribution Academy 2026https://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22z-ca-2026%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.