Deposing Dictators

Alex Martelli aleaxit at yahoo.com
Sat Aug 4 10:26:04 EDT 2001


"Moshe Zadka" <m at moshez.org> writes:
    ...
> > restrictions -- look at the complications such as StringIO vs cStringIO
> > and pickle vs cPickle that are forced by the restriction "thou shalt
> > not subclass a c-coded type":-).
> 
> How many people actually need to subclass StringIO?

Hard to get statistics, of course.  I've never done it except to
check that I could:-).

> I think the real reason StringIO stayed is "if you have trouble porting
> the C code, here's some Python instead"

If that were all, then there would be no reason to deploy and
document both modules separately on each installation; the
setup would choose the native module if it could, the pure
Python one if the native one wasn't available.  A concept that
should, I suspect, used more widely in the Python standard
libraries to promote cross-platform portability (e.g., strptime
in module time should default to a pure-Python implementation
rather than just not being there if the platform's C library does
not supply it...).

> pickle is a bit more likely to be subclassed, but not much more.

That's quite a different issue, what with persistent_id and friends!

It seems to me that the customization allowed by subclassing IS
crucial to using pickle for full-fledged persistence, in a way that
subclassing StringIO just isn't for uses of StringIO that I can
think of (indeed there's no docs, I believe, for what methods of
StringIO call self.someothermethod, so that subclassing StringIO
effectively seems to require studying sources and risking one's
code breaking on implementation upgrades).

> Again, I think the argument is that as long as we can, we want Python
> code to do the same thing for all the good reasons you know...

A very good idea (and maybe we should have more of that -- a
"Python fallback" for native-code stuff, slower but didactically
useful, sure-to-be-portable, etc etc) but not one that justifies
dual-modules, one in Python and one in C.  The "official" reason
stated in the docs for such dual-module cases (one for speed,
one for subclassing) seems more convincing to me (particularly
when such subclassing is a pressing need, as for pickle).


Alex



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the Python-list mailing list