Title: Hash a non-str name in `csv.get_dialect()` and `csv.unregister_dialect()` by jseop-lim · Pull Request #9514 · RustPython/RustPython · GitHub
Open Graph Title: Hash a non-str name in `csv.get_dialect()` and `csv.unregister_dialect()` by jseop-lim · Pull Request #9514 · RustPython/RustPython
X Title: Hash a non-str name in `csv.get_dialect()` and `csv.unregister_dialect()` by jseop-lim · Pull Request #9514 · RustPython/RustPython
Description: Closes #9507 This PR follows our AI policy Summary get_dialect and unregister_dialect turn any name that is not a str into _csv.Error without hashing it. CPython looks the name up in the registry dict with PyDict_GetItemRef and PyDict_Pop, so an unhashable name raises TypeError, a name whose __hash__ raises propagates that exception, and only a hashable name that is not registered gives unknown dialect. AS-IS >>> import csv >>> csv.get_dialect([]) _csv.Error: argument 0 must be a string, not 'list' >>> csv.unregister_dialect(BadHash()) # __hash__ raises ValueError _csv.Error: argument 0 must be a string, not 'BadHash' TO-BE >>> csv.get_dialect([]) TypeError: unhashable type: 'list' >>> csv.unregister_dialect(BadHash()) ValueError >>> csv.get_dialect(1) _csv.Error: unknown dialect (matching CPython's exception types; CPython 3.15 words the unhashable case as cannot use 'list' as a dict key (unhashable type: 'list')) Changes Add registry_key() to crates/stdlib/src/csv.rs, shared by both functions: a str name is returned as before, any other name is hashed and then reported as unknown dialect, since only str names are ever registered. Add test_dialect_name_hashing to extra_tests/snippets/stdlib_csv.py, covering an unhashable name, a name whose __hash__ raises and a hashable non-str name 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, plus threading, compared with CPython 3.15.2. The extended extra_tests/snippets/stdlib_csv.py fails on an unpatched build of that commit (at csv.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 rustpython in extra_tests: 248 pass. cargo fmt --check clean, cargo clippy -p rustpython-stdlib -- -Dwarnings reports 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 Bug Fixes CSV dialect lookups and removals now handle non-string names consistently. Unhashable names raise TypeError, and errors raised while hashing are preserved. Unknown dialect names raise a CSV error, including when unregistering a dialect while the registry is empty.
Open Graph Description: Closes #9507 This PR follows our AI policy Summary get_dialect and unregister_dialect turn any name that is not a str into _csv.Error without hashing it. CPython looks the name up in the registry...
X Description: Closes #9507 This PR follows our AI policy Summary get_dialect and unregister_dialect turn any name that is not a str into _csv.Error without hashing it. CPython looks the name up in the registry...
Opengraph URL: https://github.com/RustPython/RustPython/pull/9514
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2b1954b4-472e-0b68-2cd5-1320ccf195e1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B3AC:1D86C4:3485E75:42CAAC9:6B01DE8B |
| html-safe-nonce | 463d296110a94d02039b69cb574d2e10efee8f4293a0871c298c5a45f0b1e4cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0FDOjFEODZDNDozNDg1RTc1OjQyQ0FBQzk6NkIwMURFOEIiLCJ2aXNpdG9yX2lkIjoiNDE5MDYxOTIzNzY4Mjg5NjUyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6196a1dda43a1a49f4a7d0f6e0093358d4ec68df9d68dcc76ea05b51865fc443 |
| hovercard-subject-tag | pull_request:5104356059 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/9514/files |
| twitter:image | https://avatars.githubusercontent.com/u/86508420?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/86508420?s=400&v=4 |
| og:image:alt | Closes #9507 This PR follows our AI policy Summary get_dialect and unregister_dialect turn any name that is not a str into _csv.Error without hashing it. CPython looks the name up in the registry... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width