Repository navigation
Hash a non-str name in csv.get_dialect() and csv.unregister_dialect() - #9514
Conversation
get_dialect() and unregister_dialect() rejected any name that was not a
str with _csv.Error before looking it up. The dialect registry is a
dict, so a non-str name is first hashed: an unhashable name raises
TypeError, a name whose __hash__ raises propagates that exception, and
any other name is simply not found, raising _csv.Error("unknown
dialect").
Share the name check between both functions and hash a non-str name
before reporting it as unknown.
Assisted-by: Claude Code:claude-opus-5-5
Codex Review SummaryThis 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. |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Hash names before registry errors crates/stdlib/src/csv.rs, extra_tests/snippets/stdlib_csv.py |
A shared helper converts string names to registry keys and hashes non-string names. get_dialect and unregister_dialect use the helper. Tests check exception types, including the empty-registry case. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers: youknowone
Merge Risk: 
Minimal · up to 2ba1b
-
No merge-blocking issue is established for the dialect-name hashing changes. Merge after normal checks pass.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#9507is the only active directly linked issue.registry_key()keepsstrnames on the registry path and callsobj.hash(vm)?for non-strnames. Therefore an unhashable name or a__hash__exception propagates when the registry is non-empty. A hashable non-strname returns_csv.Error("unknown dialect").unregister_dialect()checks for an empty registry before hashing, which matches the stated CPythonPyDict_Popqualification. The added test covers both functions, unhashable names, hashing exceptions, and empty-registry misses.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff changes only
crates/stdlib/src/csv.rsandextra_tests/snippets/stdlib_csv.py. The Rust change is limited to shared key handling inget_dialect()andunregister_dialect(). The Python change adds regression coverage for the same behavior. No unrelated functional area is changed.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 04d83ee5d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Merging this PR will not alter performance
Comparing Footnotes
|
unregister_dialect() hashed a non-str name even when no dialect was registered. CPython's PyDict_Pop reports a miss on an empty dict without hashing the key, so unregister_dialect([]) raises _csv.Error there. Check for an empty registry first. Drop the snippet assertions for a hashable non-str name, which test_registry_badargs in Lib/test already covers with None. Assisted-by: Claude Code:claude-opus-5-5
csv.get_dialect()andcsv.unregister_dialect()raisecsv.Errorfor an unhashable name instead of the hashing error #9507Summary
get_dialectandunregister_dialectturn any name that is not astrinto_csv.Errorwithout hashing it. CPython looks the name up in the registry dict withPyDict_GetItemRefandPyDict_Pop, so an unhashable name raisesTypeError, a name whose__hash__raises propagates that exception, and only a hashable name that is not registered givesunknown dialect.AS-IS
TO-BE
(matching CPython's exception types; CPython 3.15 words the unhashable case as
cannot use 'list' as a dict key (unhashable type: 'list'))Changes
registry_key()tocrates/stdlib/src/csv.rs, shared by both functions: astrname is returned as before, any other name is hashed and then reported asunknown dialect, since onlystrnames are ever registered.test_dialect_name_hashingtoextra_tests/snippets/stdlib_csv.py, covering an unhashable name, a name whose__hash__raises and a hashable non-strname for both functions.Test plan
Built and run on macOS aarch64 against upstream/main 713e14c, 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.get_dialect([])) and passes with the patch and under CPython 3.15.2.rustpython -m test test_csv: 140 run, 6 skipped, all pass.pytest -k rustpythoninextra_tests: 248 pass.cargo fmt --checkclean,cargo clippy -p rustpython-stdlib -- -Dwarningsreports nothing, and the pre-commit hooks pass on both changed files.I used Claude Code (claude-opus-5-5) to draft the analysis, the patch and this description; I reviewed the change and ran every command above myself.
Summary by CodeRabbit
TypeError, and errors raised while hashing are preserved.