Title: csv: reject reentrant reader advancement by widehyo1 · Pull Request #8324 · RustPython/RustPython · GitHub
Open Graph Title: csv: reject reentrant reader advancement by widehyo1 · Pull Request #8324 · RustPython/RustPython
X Title: csv: reject reentrant reader advancement by widehyo1 · Pull Request #8324 · RustPython/RustPython
Description: Closes #8323 This PR follows our AI policy Summary RustPython's CSV reader allowed an outer next() call to continue parsing after its input iterator re-entered and advanced the same reader. CPython raises csv.Error in this situation to avoid continuing with stale reader state (see CPython gh-145105). Track the reader generation and compare the generation before and after calling the input iterator. If a reentrant call advanced the reader, raise csv.Error("iterator has already advanced the reader"), matching CPython's handling of this regression. import csv class ReentrantIterator: def __init__(self): self.reader = None self.index = 0 def __iter__(self): return self def __next__(self): self.index += 1 if self.index == 1: next(self.reader) return "a,b" if self.index == 2: return "x" raise StopIteration iterator = ReentrantIterator() reader = csv.reader(iterator) iterator.reader = reader print(next(reader)) # before: ['a', 'b'] # after: csv.Error: iterator has already advanced the reader The existing CPython regression test now passes without its expectedFailure marker. Test plan The following validation was completed by the author: Unmarks Test_Csv.test_reader_reentrant_iterator. cargo run --release Lib/test/test_csv.py: 128 tests run, 7 skipped, 18 expected failures, SUCCESS. cargo run -- extra_tests/snippets/stdlib_csv.py: passed. cargo fmt --check: passed. cargo clippy -p rustpython-stdlib --all-targets: passed with unrelated unfulfilled_lint_expectations warnings. The configured workspace test suite passed. Compared the reproducer against CPython 3.14.6. Summary by CodeRabbit Bug Fixes Improved CSV reader reliability by detecting attempts to reuse an already-advanced iterator, preventing incorrect reads. Added a clear error when the CSV reader is advanced unexpectedly during iteration.
Open Graph Description: Closes #8323 This PR follows our AI policy Summary RustPython's CSV reader allowed an outer next() call to continue parsing after its input iterator re-entered and advanced the same reader. C...
X Description: Closes #8323 This PR follows our AI policy Summary RustPython's CSV reader allowed an outer next() call to continue parsing after its input iterator re-entered and advanced the same reade...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8324
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:d688d60d-d939-c7d8-9117-fe610ae533f9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C9E2:1FB47:2D1960:3CD185:6A61349C |
| html-safe-nonce | 8d9404c848003947fb10098f498562efb92fd0ec9475162f4af6d0e9c63073a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUUyOjFGQjQ3OjJEMTk2MDozQ0QxODU6NkE2MTM0OUMiLCJ2aXNpdG9yX2lkIjoiOTA2MTg2NDU5MDk1MTkyMDc5NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fa477dc7143cf817a683abcf55bfa50da1130a16175388d496eb898ce8afafd3 |
| hovercard-subject-tag | pull_request:4085901089 |
| 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/8324/files |
| twitter:image | https://avatars.githubusercontent.com/u/87641474?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/87641474?s=400&v=4 |
| og:image:alt | Closes #8323 This PR follows our AI policy Summary RustPython's CSV reader allowed an outer next() call to continue parsing after its input iterator re-entered and advanced the same reader. C... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | c5eca2d5d770261725d2d44a57879a5bd9643e5b84204081dc36933ab40e63a2 |
| 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 | dac3a1c903b48538720e0bc780047237dd89fd4c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width