[Python-bugs-list] [ python-Bugs-553031 ] StringIO uses wrong length on non-string

noreply@sourceforge.net noreply@sourceforge.net
Fri, 10 May 2002 13:57:50 -0700


Bugs item #553031, was opened at 2002-05-06 21:33
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=553031&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Steve Holden (holdenweb)
Assigned to: Nobody/Anonymous (nobody)
Summary: StringIO uses wrong length on non-string

Initial Comment:
Brian Quinlan points out that StringIO behaves oddly 
when the argument to the creation is not of a string 
type. This is because of a bug in the __init__() 
method. The following patch appears to fix it:

Index: StringIO.py
=======================================================
============
RCS 
file: /cvsroot/python/python/dist/src/Lib/StringIO.py,v
retrieving revision 1.22
diff -r1.22 StringIO.py
45c45
<         self.len = len(buf)
---
>         self.len = len(self.buf)

In Brian's original example he was calling StringIO 
with a list argument, and getting the wrong number of 
characters back.




----------------------------------------------------------------------

>Comment By: Jeremy Hylton (jhylton)
Date: 2002-05-10 20:57

Message:
Logged In: YES 
user_id=31392

I didn't apply this patch, but isn't the line just before
the patched line "self.buf = buf".  If so, I don't see how
the patch can make a difference.

I haven't seen Brian's bug report, but StringIO can't be
called with a list as its argument.  (Well, it can, but it
will save str([]) as self.buf.)

If this is really a bug, can you include an interpreter
session where you show what goes wrong?



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=553031&group_id=5470