[New-bugs-announce] [issue12161] StringIO AttributeError instead of ValueError after close..

alejandro david weil report at bugs.python.org
Mon May 23 22:02:41 CEST 2011


New submission from alejandro david weil <tenuki at gmail.com>:

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'

----------
components: Library (Lib)
messages: 136692
nosy: tenuki
priority: normal
severity: normal
status: open
title: StringIO AttributeError instead of ValueError after close..
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12161>
_______________________________________


More information about the New-bugs-announce mailing list