mirror of https://github.com/python/cpython
make StringIO like other file objects in that readline(-1) has no effect #7348
This commit is contained in:
parent
4895af4ef1
commit
414721614f
|
@ -158,7 +158,7 @@ class StringIO:
|
|||
newpos = self.len
|
||||
else:
|
||||
newpos = i+1
|
||||
if length is not None:
|
||||
if length is not None and length > 0:
|
||||
if self.pos + length < newpos:
|
||||
newpos = self.pos + length
|
||||
r = self.buf[self.pos:newpos]
|
||||
|
|
|
@ -28,6 +28,8 @@ class TestGenericStringIO(unittest.TestCase):
|
|||
eq(self._fp.read(10), self._line[:10])
|
||||
eq(self._fp.readline(), self._line[10:] + '\n')
|
||||
eq(len(self._fp.readlines(60)), 2)
|
||||
self._fp.seek(0)
|
||||
eq(self._fp.readline(-1), self._line + '\n')
|
||||
|
||||
def test_writes(self):
|
||||
f = self.MODULE.StringIO()
|
||||
|
|
Loading…
Reference in New Issue