Feature
When a csv.reader input iterator calls next() on the same reader from its
own __next__() method, the inner call advances the reader. RustPython then
allows the outer call to continue parsing with stale reader state instead of
raising csv.Error like CPython.
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))
# CPython main:
# _csv.Error: iterator has already advanced the reader
#
# RustPython:
# ['a', 'b']
CPython rejects the outer call once it detects that the re-entrant inner call
has already advanced the reader. This prevents the outer call from continuing
with parser state that no longer belongs to it.
Python Documentation or reference to CPython source code
Drafted with AI assistance (Codex).
Feature
When a
csv.readerinput iterator callsnext()on the same reader from itsown
__next__()method, the inner call advances the reader. RustPython thenallows the outer call to continue parsing with stale reader state instead of
raising
csv.Errorlike CPython.CPython rejects the outer call once it detects that the re-entrant inner call
has already advanced the reader. This prevents the outer call from continuing
with parser state that no longer belongs to it.
Python Documentation or reference to CPython source code
_csv.reader: NULL deref via re-entrant iterator python/cpython#145105Drafted with AI assistance (Codex).