[Python-Dev] reflections on basestring -- and other abstractbasetypes

Alex Martelli aleaxit at yahoo.com
Mon Nov 3 02:54:52 EST 2003

On Sunday 02 November 2003 11:52 pm, Raymond Hettinger wrote:
> > 1. Shouldn't class UserString.UserString inherit from basestring?
> The functionality of UserString has been subsumed by inheriting from
> str.  So, its main purpose now is to keep old code working which means
> that it is probably not wise to suddenly convert it from a classic class
> to a new-style class.

OK, I guess.  The implementation doesn't offer all that much extra
convenience when compared to inheriting str, anyway -- no "factoring
out" a la DictMixin, for example.  Presumably there's little demand.

> At one time, I also requested an abstract numeric inheritance hierarchy
> with real=union(int,float,long) and numbers=union(real,complex).
> However, much time has passed and the need has never risen again.

I guess I just play too much with numbers...;-).

> > multiply inherit from basestring AND also from another builtin type
> which
> > does not in turn inherit from basestring.
> I would rather leave this open than introduce code to prevent it. My
> sense is that blocking it would introduce complexity in coding,
> documentation, understanding, and debugging while offering near zero
> payoff.

The payoff would be just in avoiding confusion.  I don't see what
complexity there could be in making each base* abstracttype
incompatible with the others -- guess I'm missing something...?

> In the C code, the actual test is for PySequence_Check() which seems to
> do a good job of finding non-mapping objects implementing __getitem__.

Unless I'm mistaken, that's exactly operator.isSequenceType(), and:

>>> import operator, UserDict
>>> operator.isSequenceType(UserDict.UserDict())

...wouldn't it be NICE to let the user help code needing to disambiguate
sequences from mappings by inheriting basesequence or basemapping...?

> operator.isMappingType
> In the meantime, I would like to remove that function from the operator
> module.  It is broken.

Yes, but isn't isSequenceType pretty iffy too...?


More information about the Python-Dev mailing list