One function

SpooledIOBase in mahmoud/boltons

The author described this change as Fix line-by-line file iteration in ioutils modules. It counts as a record because the check below fails on the code as it stood at 115cded54 and passes on 55a2791b7, with nothing else changed between the two runs.

Fix saved2017-11-10
Sharing licenceBSD-2-Clause · LICENSE
Change size+13 3

What the code was meant to do, written into the code itself as a docstring

The SpooledTempoaryFile class doesn't support a number of attributes and methods that a StringIO instance does. This brings the api as close to compatible as possible with StringIO so that it may be used as a near drop-in replacement to save memory. Another issue with SpooledTemporaryFile is that the spooled file is always a cStringIO rather than a StringIO which causes issues with some of our tools.

The change

7777 return self.buffer.isatty()
7878
7979 def next(self):
80- return self.readline()
80+ line = self.readline()
81+ if not line:
82+ pos = self.buffer.tell()
83+ self.buffer.seek(0, os.SEEK_END)
84+ if pos == self.buffer.tell():
85+ raise StopIteration
86+ else:
87+ self.buffer.seek(pos)
88+ return line
8189
8290 @property
8391 def closed(self):
122130 self.seek(pos)
123131 return val
124132
133+ __next__ = next
134+
125135 def __len__(self):
126136 return self.len
127137
128138 def __iter__(self):
129- yield self.readline()
139+ return self
130140
131141 def __enter__(self):
132142 return self
145155 def __bool__(self):
146156 return True
147157
148- __nonzero__=__bool__
158+ __nonzero__ = __bool__

The check that tells the two apart

failpass·tests/test_ioutils.py::TestSpooledBytesIO::test_iter

Check file tests/test_ioutils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it115cded54814ee5ff0b32d9bf976fd554b0a74dd
Broken version dated2017-10-11
Moduleboltons.ioutils
Units changedSpooledIOBase
Fingerprint1520c477b3bb28b6
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in mahmoud/boltons