[Python-bugs-list] [ python-Bugs-635814 ] cStringIO().write TypeError

SourceForge.net noreply@sourceforge.net
Wed, 21 May 2003 23:49:17 -0700


Bugs item #635814, was opened at 2002-11-09 03:30
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635814&group_id=5470

Category: Python Library
Group: Python 2.2.2
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: kris kvilekval (kgk)
Assigned to: M.-A. Lemburg (lemburg)
Summary: cStringIO().write TypeError

Initial Comment:


There is an incompatibilty between StringIO and 
cStringIO, as demonstrated below..  Passing an
integer to StringIO.write is OK while
it not OK to pass one to cStringIO.

$ python
Python 2.2.2 (#4, Oct 15 2002, 04:21:28) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import StringIO
>>> sfile = StringIO.StringIO()
>>> sfile.write (100)
>>> print sfile.getvalue()
100
>>> import cStringIO
>>> cfile = cStringIO.StringIO()
>>> cfile.write (100)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: write() argument 1 must be string or
read-only buffer, not int
>>> cfile.write (str(100))


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

>Comment By: Martin v. Löwis (loewis)
Date: 2003-05-22 08:49

Message:
Logged In: YES 
user_id=21627

Indeed.

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

Comment By: Brett Cannon (bcannon)
Date: 2003-05-22 04:20

Message:
Logged In: YES 
user_id=357491

If this bug cannot be fixed then shouldn't this bug report be closed?

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

Comment By: Martin v. Löwis (loewis)
Date: 2002-11-09 22:35

Message:
Logged In: YES 
user_id=21627

It's a bug that StringIO accepts it. file.write does not
support numbers, either. Unfortunately, this bug cannot be
fixed, for backwards compatibility. The conversion of any
argument to a string was originally introduced for Python
2.2, to support arbitrary buffer objects. That it also
accepts numbers now was an unexpected side effect.

Assigning to Marc-Andre, as he introduced that feature
originally.

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

Comment By: kris kvilekval (kgk)
Date: 2002-11-09 22:09

Message:
Logged In: YES 
user_id=569286

This seems like an unnecessary incompatibility,
however I guess it is there in the interest of speed?

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

Comment By: Martin v. Löwis (loewis)
Date: 2002-11-09 19:04

Message:
Logged In: YES 
user_id=21627

This is by design. The file protocol makes no guarantee that
you can write objects other than strings into a file, unless
the object explicitly documents the support for other objects.

cStringIO differs in many ways from StringIO, this is but
one way.

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

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