René's URL Explorer Experiment


Title: Show which tuple item is unhashable when a nested dict key or set element is rejected · Issue #161433 · python/cpython · GitHub

Open Graph Title: Show which tuple item is unhashable when a nested dict key or set element is rejected · Issue #161433 · python/cpython

X Title: Show which tuple item is unhashable when a nested dict key or set element is rejected · Issue #161433 · python/cpython

Description: Feature or enhancement {([1],): 1} looks contrived, but this comes up in real code as soon as a tuple key is built from existing data: row = {"user": "alice", "tags": ["a", "b"]} groups = {} groups.setdefault((row["user"], row["tags"]), ...

Open Graph Description: Feature or enhancement {([1],): 1} looks contrived, but this comes up in real code as soon as a tuple key is built from existing data: row = {"user": "alice", "tags": ["a", "b"]} groups = {} groups...

X Description: Feature or enhancement {([1],): 1} looks contrived, but this comes up in real code as soon as a tuple key is built from existing data: row = {"user": "alice", "tags": ...

Opengraph URL: https://github.com/python/cpython/issues/161433

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Show which tuple item is unhashable when a nested dict key or set element is rejected","articleBody":"### Feature or enhancement\n\n`{([1],): 1}` looks contrived, but this comes up in real code as soon as a tuple\nkey is built from existing data:\n\n```python\nrow = {\"user\": \"alice\", \"tags\": [\"a\", \"b\"]}\ngroups = {}\ngroups.setdefault((row[\"user\"], row[\"tags\"]), [])\n```\n\n```\nTypeError: cannot use 'tuple' as a dict key (unhashable type: 'list')\n```\n\nTuples are normally valid keys, so the message appears to reject the tuple because\nof a list that isn't visibly related to it. Nothing says that the list is inside\nthe tuple, or where. This was pointed out on gh-132825 and again in the PEP 814\nthread, and it is harder to follow with deeper nesting or longer tuples.\n\nI'd suggest adding a note in the error path of `tuple_hash`, following what the\n`json` module already does for nested values:\n\n```pycon\n>>> json.dumps({\"a\": [1, object()]})\nTypeError: Object of type object is not JSON serializable\nwhen serializing list item 1\nwhen serializing dict item 'a'\n\n>>> hash((\"alice\", [\"a\", \"b\"]))  # proposed\nTypeError: unhashable type: 'list'\nwhen hashing tuple item 1\n```\n\nThe note would be added only after an item's hash has failed, so successful hashing\nis unaffected. Nested tuples would produce one note per level.\n\n**Dependency on gh-149313:** the dict and set paths currently replace the exception\nand discard its notes, so the note would only become visible for dict keys and set\nelements once that issue is fixed. Until then, only direct `hash()` calls would\nshow it.\n\nReproduced on 3.14.6 and 3.15.0b2.\n\nI noticed this behavior and found it confusing myself, and the proposal is my own. I used Claude to help write this up in English and to re-check the behavior.\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n- gh-132825 (comment on nested keys): https://github.com/python/cpython/issues/132825#issuecomment-2826319275\n- PEP 814 thread: https://discuss.python.org/t/pep-814-add-frozendict-built-in-type/104854/16\n- gh-149313\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161496\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/WakaTaira","@type":"Person","name":"WakaTaira"},"datePublished":"2026-11-05T16:30:37Z","url":"https://github.com/python/cpython/issues/161433"}

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:7f5f6a3c-562a-9e99-6157-f9ef996803ad
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB18A:291B58:30E378F:3E08177:6B02028D
html-safe-noncea79e6fb8c36ce6f4cf2e78c7d44df288128a6d9926b1286e70696f9131b9d9a7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMThBOjI5MUI1ODozMEUzNzhGOjNFMDgxNzc6NkIwMjAyOEQiLCJ2aXNpdG9yX2lkIjoiMzA3MjE5ODQwMjIwNTk0MjQxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac886bf4cd8dc7a380650a0f93efc1fb8fafb52f23536c6d291916fc615dac02fc
hovercard-subject-tagissue:6227300668
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/python/cpython/161433/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0d66c627e2ba0c7c419898f77eed6b2ceb471002c3f42dd51fac4e13d8e50c46/python/cpython/issues/161433
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0d66c627e2ba0c7c419898f77eed6b2ceb471002c3f42dd51fac4e13d8e50c46/python/cpython/issues/161433
og:image:altFeature or enhancement {([1],): 1} looks contrived, but this comes up in real code as soon as a tuple key is built from existing data: row = {"user": "alice", "tags": ["a", "b"]} groups = {} groups...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameWakaTaira
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
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/python/cpython/issues/161433#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161433
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%2Fpython%2Fcpython%2Fissues%2F161433
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=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/161433
Reloadhttps://github.com/python/cpython/issues/161433
Reloadhttps://github.com/python/cpython/issues/161433
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161433
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161433
Show which tuple item is unhashable when a nested dict key or set element is rejectedhttps://github.com/python/cpython/issues/161433#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/WakaTaira
WakaTairahttps://github.com/WakaTaira
on Nov 5, 2026https://github.com/python/cpython/issues/161433#issue-6227300668
gh-132825https://github.com/python/cpython/issues/132825
gh-149313https://github.com/python/cpython/issues/149313
"unhashable type" is a beginner-unfriendly error message #132825https://github.com/python/cpython/issues/132825
"unhashable type" is a beginner-unfriendly error message #132825 (comment)https://github.com/python/cpython/issues/132825#issuecomment-2826319275
https://discuss.python.org/t/pep-814-add-frozendict-built-in-type/104854/16https://discuss.python.org/t/pep-814-add-frozendict-built-in-type/104854/16
Exception notes discarded from TypeError within __hash__() #149313https://github.com/python/cpython/issues/149313
gh-161433: Identify the failing item when hashing tuples #161496https://github.com/python/cpython/pull/161496
aiskhttps://github.com/aisk
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
on Nov 5, 2026https://github.com/python/cpython/issues/161433#event-35264123564
localzethttps://github.com/localzet
on Nov 6, 2026https://github.com/python/cpython/issues/161433#event-35359974266
pythongh-161433: Add tuple item context to hash TypeErrorhttps://github.com/localzet/cpython/commit/11500ce70c711cb04625184a80807a8ac58d1af8
pythongh-161433https://github.com/python/cpython/issues/161433
11500cehttps://github.com/localzet/cpython/commit/11500ce70c711cb04625184a80807a8ac58d1af8
pythongh-161433: Test tuple hashing exception noteshttps://github.com/localzet/cpython/commit/fce49a43369d040dd2535a2f3bfbaf2da2e4e488
pythongh-161433https://github.com/python/cpython/issues/161433
fce49a4https://github.com/localzet/cpython/commit/fce49a43369d040dd2535a2f3bfbaf2da2e4e488
pythongh-161433: Add NEWS entry and correct CI workflow formattinghttps://github.com/localzet/cpython/commit/19cf655133429641c8b319b90bb919a4761c72bd
pythongh-161433https://github.com/python/cpython/issues/161433
19cf655https://github.com/localzet/cpython/commit/19cf655133429641c8b319b90bb919a4761c72bd
pythongh-161433: Add tuple item context to hashing errorshttps://github.com/localzet/cpython/commit/cfe880a942045f352475a9cfee34fcc6c3084f37
pythongh-161433https://github.com/python/cpython/issues/161433
cfe880ahttps://github.com/localzet/cpython/commit/cfe880a942045f352475a9cfee34fcc6c3084f37
pythongh-161433: Consolidate tuple hashing note testshttps://github.com/localzet/cpython/commit/c7ce3914bbb7d3b7e4743fe917974cef286ee59a
pythongh-161433https://github.com/python/cpython/issues/161433
c7ce391https://github.com/localzet/cpython/commit/c7ce3914bbb7d3b7e4743fe917974cef286ee59a
pythongh-161433: Acknowledge original issue author WakaTairahttps://github.com/localzet/cpython/commit/0910da14a487a3a7907c2e874645ce687d65a847
pythongh-161433https://github.com/python/cpython/issues/161433
0910da1https://github.com/localzet/cpython/commit/0910da14a487a3a7907c2e874645ce687d65a847
vstinnerhttps://github.com/vstinner
on Nov 7, 2026https://github.com/python/cpython/issues/161433#event-35439765098
gh-161433: Identify the failing item when hashing tuples (#161496)https://github.com/python/cpython/commit/bd83de61433a8f6e5ae49be6ec54dc9f7d9e6aaf
gh-161433https://github.com/python/cpython/issues/161433
#161496https://github.com/python/cpython/pull/161496
bd83de6https://github.com/python/cpython/commit/bd83de61433a8f6e5ae49be6ec54dc9f7d9e6aaf
vstinnerhttps://github.com/vstinner
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 7, 2026https://github.com/python/cpython/issues/161433#event-35439840433
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/161433
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/161433
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%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.