Repository navigation
Hash a str subclass name in the csv dialect registry - #9918
Merged
Merged
Conversation
register_dialect(), get_dialect() and unregister_dialect() keyed the registry on a str name's text without hashing it, so a str subclass whose __hash__ raises was accepted. Hash every name as the dict lookup would. Assisted-by: Claude Code:claude-fable-5-2
Contributor
|
Caution Review failedThe pull request is closed.
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. |
youknowone
marked this pull request as ready for review
November 18, 2026 01:01
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
youknowone
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
register_dialect,get_dialectandunregister_dialectkey the registry on the text of astrname and hash only a name that is not astr(#9514), so astrsubclass that overrides__hash__is never hashed. CPython keeps the registry in a dict and passes the name object toPyDict_SetItem,PyDict_GetItemRefandPyDict_Pop, which call its__hash__.AS-IS
TO-BE
(matching CPython 3.15.2)
A
__hash__that returns a non-integer raisesTypeErrorin both; CPython 3.15 words it ascannot use 'StrHash' as a dict key (__hash__ method should return an integer).Changes
crates/stdlib/src/csv.rs,registry_key()hashes every name before checking that it is astr, andregister_dialect()hashes the name once the dialect is validated, where CPython inserts it.test_dialect_name_hashinginextra_tests/snippets/stdlib_csv.pywith astrsubclass whose__hash__raises, passed to all three functions, and with an invalid dialect, which is still reported first.Test plan
Built and run on macOS aarch64 against upstream/main 7abccf0, using the CI feature set
--no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,doc,ucd_3_2_0, plusthreading, compared with CPython 3.15.2.extra_tests/snippets/stdlib_csv.pyfails on an unpatched build of that commit (atcsv.register_dialect(UnhashableStr("excel"))) and passes with the patch.rustpython -m test test_csv: 140 run, 6 skipped, all pass, as on the unpatched build.cargo fmt --checkclean,cargo clippy -p rustpython-vm -p rustpython-stdlib --all-targetsreports nothing in the changed files, and the pre-commit hooks other thancspellandprettierpass on the changed files.I used Claude Code (claude-fable-5-2) to draft the analysis, the patch and this description; Claude Code ran the commands above; I reviewed the diff and their output.