Skip to content

csv: preserve dialect conversion errors and ordering - #9020

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-csv-dialect-conversion
Oct 9, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-csv-dialect-conversion

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Make CSV dialect construction collect raw attributes and keyword overrides before converting fields, using Python 3.14's lookup/conversion order.

  • Preserve exceptions from strict, doublequote, and skipinitialspace truth conversion for instances, classes, native _csv.Dialect, and dialect registration.
  • Read dialect classes directly rather than instantiating them, and skip overridden attributes before lookup or conversion.
  • Continue treating failed attribute lookup as an absent attribute and applying defaults, including the default-quoting interaction with quotechar=None.
  • Use the same ordered conversion path for keyword options and native dialect construction, retaining original exception objects.

This is a coherent replacement of the existing duplicated dialect-conversion paths. A one-line strict propagation change is insufficient: the old parser also replaces exceptions, instantiates class inputs, and converts overridden attributes before applying keyword options. The shared path removes the duplicated conversion code.

The strict-conversion issue was identified while auditing #8954. That PR's attribute-lookup propagation was intentionally not copied because CPython 3.14 ignores attribute lookup failures here.

Validation

Base: bd8fdb7e5ca3e4e9f78f4f34b122a84c9dd2e2d0.
Head: 62a324e740cf0f19a219e358304bce24bd0212de.
Reference: CPython 3.14.7, Linux x86_64.

  • The new regression in the existing extra_tests/snippets/stdlib_csv.py fails the separately built, immutable current-main executable because a strict.__bool__ exception is suppressed.
  • The complete CSV snippet passes patched RustPython and CPython 3.14.7 through the actual pytest snippet runner.
  • Unmodified canonical -m test test_csv passes on baseline and patched RustPython: 134 tests, 6 skips. Existing expected-failure marking is unchanged.
  • Observation tests match CPython's field lookup/conversion order, lookup failures, class handling, keyword override behavior, and exception precedence.
  • Independent 432-case constructor review covers _csv.Dialect, reader, and writer, with 8 fields and 18 values per field. Baseline differs on 242 cases; patched semantic outcomes match all 432. The remaining 21 text-only differences are 18 preexisting validation-error wordings and 3 generic Rust integer-overflow messages versus CPython's C-int wording.
  • Unknown keyword and excess reader/writer positional arguments fail before truth conversion.

This does not change the preexisting non-ASCII delimiter limitation, native-dialect identity behavior, or unrelated CSV parsing/writing paths. Broad Rust runtime suites were not executed; only focused CSV runtime checks and compile-only aggregates are used.

Additional checks passed:

  • cargo clippy --locked --release -p rustpython-stdlib --all-targets -- -D warnings
  • cargo test --locked --release --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi --no-run
  • From crates/capi: cargo test --locked --release --no-run
  • Normal commit hooks passed without changing the tested source or regression file.

AI assistance

OpenAI Codex assisted with the audit, implementation, regression tests, and validation. The runtime checks above were actually executed in the Linux environment; no untested platform behavior is claimed.

Collect raw dialect fields and keyword overrides before converting them in CPython 3.14 order. Preserve truth-conversion exceptions, read classes without instantiating them, and retain defaulting for failed attribute lookup.

Use one shared parser for reader, writer, registry, and native dialect construction. Extend the existing CSV snippet with class, instance, direct-construction, lookup, override, conversion-order, and argument-binding regressions.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 99814ff9-bc13-4d5b-ad68-ce16d35e2a87

📥 Commits

Reviewing files that changed from the base of the PR and between bd8fdb7 and 62a324e.


📒 Files selected for processing (2)
  • crates/stdlib/src/csv.rs
  • extra_tests/snippets/stdlib_csv.py

 ___________________________
< Domesticating the T-1000. >
 ---------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ 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.

❤️ Share

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

@codspeed

codspeed Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix-csv-dialect-conversion (62a324e) with main (bd8fdb7)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 9, 2026 14:28
@youknowone
youknowone merged commit 8986de2 into RustPython:main Oct 9, 2026
22 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T14:36:10.978932Z 62a324e Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants