(original) (raw)
On Sat, Mar 3, 2012 at 13:02, Antoine Pitrou <solipsis@pitrou.net> wrote:
-- On Sat, 3 Mar 2012 12:59:13 -0800Ironically, most of the confusion stems from sequence types
Thomas Wouters <thomas@python.org> 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,
> but all it seems to do now is create confusion, what with many sequence
> types implementing both, and PyMapping\_Check() and PySequence\_Check() doing
> seemingly random things to come up with somewhat sensible answers.
implementing the mapping protocol for extended slicing.
It seems to be a leftover:
> Do note
> that the dict type actually implements tp\_as\_sequence (in order to support
> containtment tests) and that PySequence\_Check() has to explicitly return 0
> for dicts -- which means that it will give the "wrong" answer for another
> type that behaves exactly like dicts.
int
PySequence\_Check(PyObject \*s)
{
if (PyDict\_Check(s))
return 0;
return s != NULL && s->ob\_type->tp\_as\_sequence &&
s->ob\_type->tp\_as\_sequence->sq\_item != NULL;
}
Dict objects have a NULL sq\_item so even removing the explicit check
would still return the right answer.
This proposal sounds rather backwards, given that we now have separate
> Getting rid of the misleading distinction seems like a much better idea
> than trying to re-conflate some of the issues.
Mapping and Sequence ABCs.
I'm not sure how the ABCs, which are abstract declarations of semantics, tie into this specific implementation detail. ABCs work just as well for Python types as for C types, and Python types don't have this distinction. The distinction in C types has been \*practically\* useless for years, so why should it stay? What is the actual benefit here?
Thomas Wouters <thomas@python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!