Issue 12161: StringIO AttributeError instead of ValueError after close.. (original) (raw)

Issue12161

Created on 2011-05-23 20:02 by tenuki, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
12161.patch catalin.iacob,2011-05-25 20:27 review
Messages (4)
msg136692 - (view) Author: alejandro david weil (tenuki) Date: 2011-05-23 20:02
python 2.7 documentation: file:///usr/share/doc/python-doc/html/library/stringio.html#StringIO.StringIO.close (or: http://docs.python.org/library/stringio.html#StringIO.StringIO.close ) says: """StringIO.close() Free the memory buffer. Attempting to do further operations with a closed StringIO object will raise a ValueError.""" But this code: def string_io_close_exception_test(): from StringIO import StringIO s=StringIO() s.write("asdf") s.close() try: # file:///usr/share/doc/python-doc/html/library/stringio.html#StringIO.StringIO.close doc = """ StringIO.close() Free the memory buffer. Attempting to do further operations with a closed StringIO object will raise a ValueError. """ s.getvalue() except ValueError: print "this is the expected" except Exception, e: print 'this is unexpected:',type(e), e raise produces this output: this is unexpected: <type 'exceptions.AttributeError'> StringIO instance has no attribute 'buf' Traceback (most recent call last): File "problems.py", line 192, in string_io() File "problems.py", line 184, in string_io s.getvalue() File "/usr/lib/python2.7/StringIO.py", line 270, in getvalue self.buf += ''.join(self.buflist) AttributeError: StringIO instance has no attribute 'buf'
msg136895 - (view) Author: Catalin Iacob (catalin.iacob) * Date: 2011-05-25 20:27
Attached patch + test case. Also tested cStringIO in 2.7 and io.StringIO in 3.2 and 3.3 tip and they aren't affected.
msg136934 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-05-26 09:07
I tested the patch on current 2.7 tip. It works and looks good to me.
msg136972 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-26 14:57
New changeset 720804a91c01 by Benjamin Peterson in branch '2.7': raise an ValueError in getvalue() on closed StringIO (closes #12161) http://hg.python.org/cpython/rev/720804a91c01
History
Date User Action Args
2022-04-11 14:57:17 admin set github: 56370
2011-05-26 14:57:10 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2011-05-26 09:07:44 petri.lehtinen set nosy: + pitrou, benjamin.peterson, stutzbach, petri.lehtinenmessages: +
2011-05-25 20:27:36 catalin.iacob set files: + 12161.patchnosy: + catalin.iacobmessages: + keywords: + patch
2011-05-23 20:02:41 tenuki create