[Python-Dev] slice subscripts for sequences and mappings (original) (raw)
Thomas Wouters thomas at python.org
Sun Mar 4 03:20:22 CET 2012
- Previous message: [Python-Dev] slice subscripts for sequences and mappings
- Next message: [Python-Dev] slice subscripts for sequences and mappings
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Mar 3, 2012 at 13:02, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Sat, 3 Mar 2012 12:59:13 -0800 Thomas Wouters <thomas at python.org> wrote: > > Why even have separate tpassequence and tpasmapping 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 PyMappingCheck() and PySequenceCheck() doing > seemingly random things to come up with somewhat sensible answers.
Ironically, most of the confusion stems from sequence types implementing the mapping protocol for extended slicing. > Do note > that the dict type actually implements tpassequence (in order to support > containtment tests) and that PySequenceCheck() has to explicitly return 0 > for dicts -- which means that it will give the "wrong" answer for another > type that behaves exactly like dicts. It seems to be a leftover: int PySequenceCheck(PyObject *s) { if (PyDictCheck(s)) return 0; return s != NULL && s->obtype->tpassequence && s->obtype->tpassequence->sqitem != NULL; } Dict objects have a NULL sqitem so even removing the explicit check would still return the right answer. > Getting rid of the misleading distinction seems like a much better idea > than trying to re-conflate some of the issues. This proposal sounds rather backwards, given that we now have separate 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 at python.org>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20120303/2b1b40d7/attachment.html>
- Previous message: [Python-Dev] slice subscripts for sequences and mappings
- Next message: [Python-Dev] slice subscripts for sequences and mappings
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]