Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6065d32

Browse files
committed
SF bug #951915: fix bug in StringIO.truncate - length not changed
(Patch by Armin Rigo.)
1 parent 2ccea17 commit 6065d32

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

Lib/StringIO.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def truncate(self, size=None):
204204
elif size < self.pos:
205205
self.pos = size
206206
self.buf = self.getvalue()[:size]
207+
self.len = size
207208

208209
def write(self, s):
209210
"""Write a string to the file.
@@ -312,6 +313,11 @@ def test():
312313
print 'File length =', f.tell()
313314
if f.tell() != length:
314315
raise RuntimeError, 'bad length'
316+
f.truncate(length/2)
317+
f.seek(0, 2)
318+
print 'Truncated length =', f.tell()
319+
if f.tell() != length/2:
320+
raise RuntimeError, 'truncate did not adjust length'
315321
f.close()
316322

317323
if __name__ == '__main__':

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Extension Modules
3030
Library
3131
-------
3232

33+
- StringIO.truncate() now correctly adjusts the size attribute.
34+
(Bug #951915).
35+
3336
- locale.py now uses an updated locale alias table (built using
3437
Tools/i18n/makelocalealias.py, a tool to parse the X11 locale
3538
alias file); the encoding lookup was enhanced to use Python's

0 commit comments

Comments
 (0)