[Python-Dev] slice subscripts for sequences and mappings

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Mar 4 22:14:31 CET 2012


Thomas Wouters wrote:

> Why even have separate tp_as_sequence and tp_as_mapping anymore? That 
> particular distinction never existed for Python types, so why should it 
> exist for C types at all? I forget if there was ever a real point to it,

I imagine the original motivation was to provide a fast path
for types that take ints as indexes. Also, it dates from the
very beginnings of Python, before it had user defined classes.
At that time the archetypal sequence (list) and the archetypal
mapping (dict) were very distinct -- I don't think dicts
supported 'in' then, so there was no overlap. It looks like a
case of "it seemed like a good idea at the time".

The distinction broke down fairly soon after, but it's so
embedded in the extension module API that it's been very hard
to get rid of.

-- 
Greg


More information about the Python-Dev mailing list