[Python-Dev] Need a way to test for 8-bit-or-unicode-string

M.-A. Lemburg mal@lemburg.com
Fri, 05 Oct 2001 18:57:20 +0200


"Barry A. Warsaw" wrote:
> 
> >>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
> 
>     GvR> I'm currently +1 on introducing names for abstract base
>     GvR> classes *and* extensing isinstance()'s API.
> 
> I'm worried about the abstract base class idea, because it might lead
> us down a path of having a complicated class hierarchy in order to
> provide completeness.

Since these are abstract classes (basically names for what
we now loosly call interface, e.g. file-like object, sequence-like
object etc.) this very shallow hierarchy wouldn't hurt all that
much.

Sure, strings are sequences, so they stringbase would have
to be a subclass of sequencebase, but I don't think we'll ever
get more than 3 levels deep in the abstract class hierarchy.
 
> E.g. should "strings" be a sequencebase, as well as a stringbase?  And
> what does a sequencebase /mean/?

Good point. There's PySequence_Check(), but we'll have to discuss
this at some point anyway and come up with definitions for the currently
used fuzzy terms "sequence", "number", "string", and so on.
 
> Will we push to try to include protocols/interfaces into this mix, so
> that we'll end up defining abstract classes for all the deep-mojo
> interfaces?  Maybe we'll want to have abstract base classes for file
> objects so things like file and StringIO's can have them as a common
> base class?
> 
> In any event, I think the isinstance() extension is a simple, clean,
> and (mostly :) uncontroversial change, so I'm also +1 on doing that
> now.
> 
> Adding a set of abstract base classes and hooking them up with the
> existing concrete data types seems much murkier to me, and of greater
> long range impact, so I'm -1 on the idea, at least until it gets
> PEP'd.

Are you sure about the -1 ? Using abstract base classes seems like
a natural thing to do in an OO-language like Python while the
isinstance() hack would not allow you to use your own UserList
subclass for code which was written with sequences as input.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/