[Python-checkins] python/dist/src/Modules cStringIO.c,2.42,2.43

Skip Montanaro skip at pobox.com
Mon Aug 11 10:37:40 EDT 2003

>>>>> "Just" == Just van Rossum <just at letterror.com> writes:

    Just> montanaro at users.sourceforge.net wrote:
    >> Modified Files:
    >> cStringIO.c 
    >> Log Message:
    >> shit - just change the visible name, not the comments - strictly
    >> speaking, the tp_name is not correct, but what's exposed to users is
    >> known visibly as "StringIO", not "StringI" or "StringO".

    Just> And now there are two distinct types with the same name. What's
    Just> the point of that?

Yes, but I believe those names are only used in stuff like tracebacks.
StringO and StringI are not documented as user-visible types:

    >>> import cStringIO
    >>> dir(cStringIO)
    ['InputType', 'OutputType', 'StringIO', '__doc__', '__file__',
    '__name__', 'cStringIO_CAPI'] 

so displaying them in tracebacks is at best confusing.  It's simply an
implementation detail that under the covers different types are used when
reading and writing:

    >>> type(cStringIO.StringIO("sdfsfd"))
    <type 'cStringIO.StringI'>
    >>> type(cStringIO.StringIO())
    <type 'cStringIO.StringO'>

On the other hand, I can see that this would be confusing:

    >>> t = cStringIO.StringIO()
    >>> t.write("bar")
    >>> s = cStringIO.StringIO("sdfsfd") 
    >>> s.write("bar")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    AttributeError: 'cStringIO.StringIO' object has no attribute 'write'

whereas before my checkin the traceback would at least name a different

    AttributeError: 'cStringIO.StringI' object has no attribute 'write'

Maybe my change was hasty.  If so, mention of StringI and StringO should be
made in the StringIO/cStringIO docs.


More information about the Python-checkins mailing list