Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cStringIO class name typo #49595

Closed
qwjqwj mannequin opened this issue Feb 22, 2009 · 4 comments
Closed

cStringIO class name typo #49595

qwjqwj mannequin opened this issue Feb 22, 2009 · 4 comments
Labels
stdlib Python modules in the Lib dir

Comments

@qwjqwj
Copy link
Mannequin

qwjqwj mannequin commented Feb 22, 2009

BPO 5345
Nosy @avassalotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-04-03.21:20:33.917>
created_at = <Date 2009-02-22.07:09:35.801>
labels = ['library']
title = 'cStringIO class name typo'
updated_at = <Date 2009-04-03.21:20:33.916>
user = 'https://bugs.python.org/qwjqwj'

bugs.python.org fields:

activity = <Date 2009-04-03.21:20:33.916>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2009-04-03.21:20:33.917>
closer = 'benjamin.peterson'
components = ['Library (Lib)']
creation = <Date 2009-02-22.07:09:35.801>
creator = 'qwjqwj'
dependencies = []
files = []
hgrepos = []
issue_num = 5345
keywords = []
message_count = 4.0
messages = ['82595', '82596', '82600', '85297']
nosy_count = 3.0
nosy_names = ['alexandre.vassalotti', 'vdupras', 'qwjqwj']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue5345'
versions = ['Python 2.5']

@qwjqwj
Copy link
Mannequin Author

qwjqwj mannequin commented Feb 22, 2009

It has a typo error in cStringIO.StringIO's class name "StringO":

>>> import cStringIO
>>> a=cStringIO.StringIO()
>>> a
<cStringIO.StringO object at 0xb7eef240>
>>> a.__class__.__name__
'StringO'

So we can't unpickle the object correctly with Python 2.5.4:

>>> import pickle
>>> pickle.loads(pickle.dumps(a))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/pickle.py", line 1366, in dumps
    Pickler(file, protocol).dump(obj)
  File "/usr/local/lib/python2.5/pickle.py", line 224, in dump
    self.save(obj)
  File "/usr/local/lib/python2.5/pickle.py", line 306, in save
    rv = reduce(self.proto)
  File "/usr/local/lib/python2.5/copy_reg.py", line 69, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle StringO objects

When using multiprocess library, it also use the pickling and unpickling
of cStringIO.StringIO object

@qwjqwj qwjqwj mannequin added the stdlib Python modules in the Lib dir label Feb 22, 2009
@qwjqwj
Copy link
Mannequin Author

qwjqwj mannequin commented Feb 22, 2009

This bug also exists in Python 2.6.1

@vdupras
Copy link
Mannequin

vdupras mannequin commented Feb 22, 2009

The documentation says:

"Another difference from the StringIO module is that calling StringIO()
with a string parameter creates a read-only object. Unlike an object
created without a string parameter, it does not have write methods. These
objects are not generally visible. They turn up in tracebacks as StringI
and StringO."

And there seem to have been some activity about this around r33834.

@avassalotti
Copy link
Member

This is not a typo. cStringIO.StringIO is a factory function that
returns either a cStringO object (for writing) or cStringI (for
reading). If this behavior causes a problem to you, then consider using
StringIO.StringIO.

Alternatively, you could upgrade to Python 2.7 or 3.0 and use
io.StringIO() which doesn't have this limitation.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants