Issue 8382: StringIO.write() takes any argument and converts it to a string (original) (raw)

Created on 2010-04-12 23:56 by tarek, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg102991 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2010-04-12 23:56
Looks like the python version of StringIO can write tuples, but not the C version. I am not sure this is intended: >>> from cStringIO import StringIO as cStringIO >>> from StringIO import StringIO as StringIO >>> string = StringIO() >>> string.write(('my', 'tuple')) >>> cstring = cStringIO() >>> cstring.write(('my', 'tuple')) Traceback (most recent call last): File "", line 1, in TypeError: write() argument 1 must be string or read-only character buffer, not tuple
msg102993 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-13 00:05
Probably not. I guess an implicit str() is done on the argument given to write(): >>> s = StringIO() >>> s.write((1,2)) >>> s.write(3) >>> s.getvalue() '(1, 2)3'
msg102994 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2010-04-13 00:10
Yes, I am not sure what would be the best fix though. We cannot raise an error on StringIO now because this will break lots of code out there. In the meantime, I think it's cleaner to avoid doing implicit str() conversions, so I think cStringIO has a better approach. I would be in favor of a status quo for 2.x
msg103005 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-04-13 03:01
It's clear you can't change it for 2.6 or 2.7, almost certainly not 3.1. Maybe you could change it for 3.2.
msg103006 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-04-13 03:04
Whoops. No stringio.py in 3.x. This should be closed as won't fix since it's not a problem in py3k and can't be changed in 2.x.
History
Date User Action Args
2022-04-11 14:56:59 admin set github: 52629
2010-04-13 12:09:14 r.david.murray set status: open -> closedresolution: wont fixstage: resolved
2010-04-13 03:04:50 skip.montanaro set messages: +
2010-04-13 03:01:05 skip.montanaro set nosy: + skip.montanaromessages: +
2010-04-13 00:10:18 tarek set messages: +
2010-04-13 00:07:49 pitrou set title: cStringIO and StringIO don't behave the same way -> StringIO.write() takes any argument and converts it to a string
2010-04-13 00:05:13 pitrou set priority: normalnosy: + pitroumessages: +
2010-04-12 23:56:59 tarek set title: cStringIO and StringIO doesn't behave the same way -> cStringIO and StringIO don't behave the same way
2010-04-12 23:56:51 tarek create