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

Alex Martelli aleaxit at yahoo.com
Mon Nov 3 03:40:02 EST 2003


On Monday 03 November 2003 09:16 am, Raymond Hettinger wrote:
   ...
> type and another builtin type.  Does anyone other than you, me, Armin,
> and Tim even use multiple inheritance?  This basically never comes up

I think you're not very acquainted with people coming from C++ or Eiffel...

> > Yes, but isn't isSequenceType pretty iffy too...?
>
> Nope.
>
> >>> import operator
> >>> map(operator.isSequenceType, [(), [], 'ab', u'ab', {}, 1])
>
> [True, True, True, True, False, False]
>
> >>> map(operator.isMappingType, [(), [], 'ab', u'ab', {}, 1])
>
> [True, True, True, True, True, False]
>
> The first is 100% correct.
> The second has four false positives.

Right: isSequenceType works on built-ins, isMappingType doesn't.


> For user defined classes implementing __getitem__, neither function can
> distinguish between a mapping or a sequence.   This is the best they can
> do.

OK -- so, if we had basesequence and basemapping, the user COULD help
make the distinction totally reliable (if multiply inheriting from both was
allowed, the user could also make a total unusable muddle of course:-).


Alex




More information about the Python-Dev mailing list