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.
Projectmahmoud/boltons
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
| 77 | 77 | return self.buffer.isatty() | |
| 78 | 78 | ||
| 79 | 79 | 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 | |
| 81 | 89 | ||
| 82 | 90 | @property | |
| 83 | 91 | def closed(self): | |
| ⋯ | |||
| 122 | 130 | self.seek(pos) | |
| 123 | 131 | return val | |
| 124 | 132 | ||
| 133 | + | __next__ = next | |
| 134 | + | ||
| 125 | 135 | def __len__(self): | |
| 126 | 136 | return self.len | |
| 127 | 137 | ||
| 128 | 138 | def __iter__(self): | |
| 129 | - | yield self.readline() | |
| 139 | + | return self | |
| 130 | 140 | ||
| 131 | 141 | def __enter__(self): | |
| 132 | 142 | return self | |
| ⋯ | |||
| 145 | 155 | def __bool__(self): | |
| 146 | 156 | return True | |
| 147 | 157 | ||
| 148 | - | __nonzero__=__bool__ | |
| 158 | + | __nonzero__ = __bool__ | |
The check that tells the two apart
fail→pass·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
- 2026-08-06Bits
- 2026-08-06JSONLIterator
- 2026-08-06tableutils: fix Table.to_text crashes on degenerate tables and headers
- 2026-07-18backoff_iter
- 2026-07-17singularize
- 2026-07-17fix(fileutils): accept os.PathLike in AtomicSaver