René's URL Explorer Experiment


Title: set/frozenset re-hash elements when constructed from a set, frozenset, or dict · Issue #8489 · RustPython/RustPython · GitHub

Open Graph Title: set/frozenset re-hash elements when constructed from a set, frozenset, or dict · Issue #8489 · RustPython/RustPython

X Title: set/frozenset re-hash elements when constructed from a set, frozenset, or dict · Issue #8489 · RustPython/RustPython

Description: Summary set/frozenset recompute __hash__ for every element when the source is a set, frozenset, or dict. CPython reuses the hash already stored in the source's entries (set_update_internal in Objects/setobject.c, branching on PyAnySet_Ch...

Open Graph Description: Summary set/frozenset recompute __hash__ for every element when the source is a set, frozenset, or dict. CPython reuses the hash already stored in the source's entries (set_update_internal in Objec...

X Description: Summary set/frozenset recompute __hash__ for every element when the source is a set, frozenset, or dict. CPython reuses the hash already stored in the source's entries (set_update_internal in O...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"set/frozenset re-hash elements when constructed from a set, frozenset, or dict","articleBody":"## Summary\n\n`set`/`frozenset` recompute `__hash__` for every element when the source is a `set`, `frozenset`, or `dict`. CPython reuses the hash already stored in the source's entries (`set_update_internal` in `Objects/setobject.c`, branching on `PyAnySet_Check` / `PyDict_CheckExact`), so no extra `__hash__` calls happen.\n\n## Scope\n\nThe set/frozenset target only. The `dict` target (`dict.fromkeys`) is #8490. `test_do_not_rehash_dict_keys` asserts on both directions, so its `@unittest.expectedFailure  # TODO: RUSTPYTHON` marker can only be dropped once both are done.\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\nfrozenset(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`, inherited by `TestSet`, `TestSetSubclass`, `TestFrozenSet` and `TestFrozenSetSubclass` (4 of the 10 expected failures in `test_set.py`).\n\n## Analysis\n\nThe hash is already stored — `DictEntry` keeps it next to the key (`crates/vm/src/dict_inner.rs:227`), and `PySetInner::update_internal` (`crates/vm/src/builtins/set.rs:379`) already special-cases `AnySet` and `PyDict`. But both branches drop it and go through `self.add()` → `content.insert()`, which re-hashes:\n\n```rust\nfn merge_set(&self, any_set: AnySet, vm: &VirtualMachine) -> PyResult\u003c()> {\n    for item in any_set.as_inner().elements() {\n        self.add(item, vm)?;      // recomputes the hash\n    }\n    Ok(())\n}\n```\n\n`update_internal` is also only reached from `set.update()` (`:719`). These paths never dispatch on the source type at all:\n\n- `PySetInner::from_iter` (`:187`), used by the `set()` / `frozenset()` constructors\n- `union` (`:252`), `intersection` (`:261`), `difference` (`:272`), `symmetric_difference` (`:280`)\n- `intersection_update` (`:409`), `difference_update` (`:422`), `symmetric_difference_update` (`:436`)\n","author":{"url":"https://github.com/fregataa","@type":"Person","name":"fregataa"},"datePublished":"2026-08-10T16:49:30Z","url":"https://github.com/RustPython/RustPython/issues/8489"}

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:11b3a79c-06ef-aee4-1452-fd6736e45fa6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA030:317608:3D915AD:4DED5D2:6B0206BC
html-safe-nonce06181a4c291a6081dd0b4edaa51718b340aac3f48b18c2dbb3f5bdff3f26b091
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDMwOjMxNzYwODozRDkxNUFEOjRERUQ1RDI6NkIwMjA2QkMiLCJ2aXNpdG9yX2lkIjoiNzU2NDA5NzA1Njg5ODQxODM2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3ff96f447671928142858c788a309e964d0a2de62b96234bd3e24eea98b344d4
hovercard-subject-tagissue:5112413997
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/8489/issue_layout
twitter:imagehttps://opengraph.githubassets.com/158efbf61676fa6cf2fd044ba43ef27cf2c3d1f76677d2be4bf98fa392971831/RustPython/RustPython/issues/8489
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/158efbf61676fa6cf2fd044ba43ef27cf2c3d1f76677d2be4bf98fa392971831/RustPython/RustPython/issues/8489
og:image:altSummary set/frozenset recompute __hash__ for every element when the source is a set, frozenset, or dict. CPython reuses the hash already stored in the source's entries (set_update_internal in Objec...
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/8489#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F8489
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%2F8489
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/8489
Reloadhttps://github.com/RustPython/RustPython/issues/8489
Reloadhttps://github.com/RustPython/RustPython/issues/8489
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/8489
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8489
#8852https://github.com/RustPython/RustPython/pull/8852
#8491https://github.com/RustPython/RustPython/pull/8491
set/frozenset re-hash elements when constructed from a set, frozenset, or dicthttps://github.com/RustPython/RustPython/issues/8489#top
#8852https://github.com/RustPython/RustPython/pull/8852
#8491https://github.com/RustPython/RustPython/pull/8491
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 10, 2026https://github.com/RustPython/RustPython/issues/8489#issue-5112413997
#8490https://github.com/RustPython/RustPython/issues/8490
fregataahttps://github.com/fregataa
on Aug 11, 2026https://github.com/RustPython/RustPython/issues/8489#event-29278154542
Reuse stored hashes when building a set from a set/frozenset/dicthttps://github.com/fregataa/RustPython/commit/2924f86ff184e5b28eb684d1e32237f318f4b537
https://docs.github.com/articles/closing-issues-via-commit-messages
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/8489#event-29281152159
youknowonehttps://github.com/youknowone
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8489#event-29324866228
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
https://docs.github.com/articles/closing-issues-via-commit-messages
7612e68https://github.com/RustPython/RustPython/commit/7612e68357e4d7b8c386eb7785d000f5fcfe6f8d
youknowonehttps://github.com/youknowone
completedhttps://github.com/RustPython/RustPython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#8491https://github.com/RustPython/RustPython/pull/8491
on Aug 12, 2026https://github.com/RustPython/RustPython/issues/8489#event-29324866235
youknowonehttps://github.com/youknowone
on Sep 16, 2026https://github.com/RustPython/RustPython/issues/8489#event-31263099911
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
https://docs.github.com/articles/closing-issues-via-commit-messages
856c3dahttps://github.com/RustPython/RustPython/commit/856c3da0beacb47c34a1fcf19b9cffb86988749f
Sign up for freehttps://github.com/signup?return_to=https://github.com/RustPython/RustPython/issues/8489
Sign in to commenthttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8489
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.