Skip to content

Reuse stored hashes in dict.fromkeys() - #8503

Draft
fregataa wants to merge 1 commit into
RustPython:mainfrom
fregataa:fromkeys-known-hash
Draft

Reuse stored hashes in dict.fromkeys()#8503
fregataa wants to merge 1 commit into
RustPython:mainfrom
fregataa:fromkeys-known-hash

Conversation

@fregataa

@fregataa fregataa commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

dict.fromkeys() recomputed hash for every key even when the source already stored a hash per entry. CPython's _PyDict_FromKeys branches on PyDict_CheckExact / PyAnySet_CheckExact and feeds the hash read from the source table straight into insertdict; RustPython always iterated generically through setitem.

The checks are the exact ones CPython uses: a set or dict subclass may override iter, so reading its table directly would change what the call observes. exact_set_keys_with_hashes() is therefore separate from extract_set(), which stays subclass-inclusive for the set operations.

@fregataa
fregataa marked this pull request as draft August 12, 2026 13:17
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 85b829a8-e729-4733-869c-681af8632991

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_set.py (TODO: 3)

dependencies:

dependent tests: (no tests depend on set)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Closes RustPython#8490.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@fregataa
fregataa force-pushed the fromkeys-known-hash branch from fe77067 to 324ecaa Compare August 12, 2026 13:23
@moreal moreal added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dict.fromkeys() re-hashes keys taken from a set, frozenset, or dict

2 participants