This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: StringIO AttributeError instead of ValueError after close..
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, catalin.iacob, petri.lehtinen, pitrou, python-dev, stutzbach, tenuki
Priority: normal Keywords: patch

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 <module>
    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:17adminsetgithub: 56370
2011-05-26 14:57:10python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg136972

resolution: fixed
stage: resolved
2011-05-26 09:07:44petri.lehtinensetnosy: + pitrou, benjamin.peterson, stutzbach, petri.lehtinen
messages: + msg136934
2011-05-25 20:27:36catalin.iacobsetfiles: + 12161.patch

nosy: + catalin.iacob
messages: + msg136895

keywords: + patch
2011-05-23 20:02:41tenukicreate