[Python-Dev] operator.is*Type
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Feb 23 05:27:33 CET 2006
Fuzzyman wrote:
> The operator module defines two functions :
>
> isMappingType
> isSquenceType
>
> These protocols are loosely defined. Any object which has a
> ``__getitem__`` method defined could support either protocol.
These functions are actually testing for the presence
of two different __getitem__ methods at the C level, one
in the "mapping" substructure of the type object, and the
other in the "sequence" substructure. This only works
for types implemented in C which make use of this distinction.
It's not much use for user-defined classes, where the
presence of a __getitem__ method causes both of these
slots to become populated.
Having two different slots for __getitem__ seems to have
been an ill-considered feature in the first place and
would probably best be removed in 3.0. I wouldn't mind if
these two functions went away.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | Carpe post meridiam! |
Christchurch, New Zealand | (I'm not a morning person.) |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list