[Python-bugs-list] [Bug #116787] StringIO does not check constructor argument type
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 13 Oct 2000 07:07:23 -0700
Bug #116787, was updated on 2000-Oct-13 06:33
Here is a current snapshot of the bug.
Project: Python
Category: Library
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Summary: StringIO does not check constructor argument type
Details: Python 2.0c1 (#7, Oct 9 2000, 18:44:43) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> import StringIO
>>> file = open("C:/Python20/readme.txt")
>>> fstr = StringIO.StringIO(file.readlines())
# The above line differs from the behavior of cStringIO, which correctly
# reports: "TypeError: expected string, list found"
# Doom is inevitable after this...
>>> len(fstr.getvalue())
838
>>> fstr.readline()
Traceback (innermost last):
File "<pyshell#4>", line 1, in ?
fstr.readline()
File "c:\python20\lib\StringIO.py", line 85, in readline
i = string.find(self.buf, '\n', self.pos)
File "c:\python20\lib\string.py", line 172, in find
return s.find(*args)
AttributeError: find
>>>
Follow-Ups:
Date: 2000-Oct-13 07:07
By: fdrake
Comment:
I'm not convinced this is a bug. Is there a reason StringIO should not accept any sequence object that returns characters for each position? Unicode and UserString objects should be acceptable. This seems particularly difficult to test for up front. I think the allowance of only 8-bit strings should be documented as a limitation of the currrent implementation of cStringIO.
Guido will need to make a pronouncement here. Adding a test for the input type being a string or Unicode object would be easy enough. Guido, feel free to assign back to me to handle this based on your decision.
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=116787&group_id=5470