[New-bugs-announce] [issue27261] io.BytesIO.truncate does not work as advertised

Justus Winter report at bugs.python.org
Tue Jun 7 16:52:57 EDT 2016


New submission from Justus Winter:

% python3.6 -c "import io; b=io.BytesIO(); assert b.truncate(42) == 42; assert len(b.getbuffer()) == 42, 'expected length 42, got {}'.format(len(b.getbuffer()))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AssertionError: expected length 42, got 0

The documentation [0] says that truncate can extend objects, and there is no indication that BytesIO does not support that.  As demonstrated, truncate returns the new size, but the buffer obtained from that BytesIO is of size zero (likewise, b.getvalue() returns b''.

0: https://docs.python.org/3.6/library/io.html#io.IOBase.truncate

----------
components: IO, Library (Lib)
messages: 267748
nosy: justus.winter
priority: normal
severity: normal
status: open
title: io.BytesIO.truncate does not work as advertised
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27261>
_______________________________________


More information about the New-bugs-announce mailing list