
On 30/12/20 9:44 am, Christopher Barker wrote:
So there are dunders, and protocols, and ABCs, and they all overlap a bit in purpose. And "protocols" seem to be the least clearly specified.
there are various protocols described in the C API docs, including the Mapping protocol:
https://docs.python.org/3/c-api/mapping.html <https://docs.python.org/3/c-api/mapping.html>
But I *think* that's really about the C API -- not what we are talking about here.
The library reference doesn't seem to use the terms "sequence protocol" and "mapping protocol". It talks about "sequence types" and "mapping types", but doesn't use the word "protocol" in relation to them. Nor is there any clear list of methods that a type needs to provide in order to be considered a sequence or mapping. There are lists of operations supported by the built-in container types, but those are fairly extensive, and it's not obvious which ones are vital. So are the "sequence protocol" and "mapping protocol" really mythical beasts that don't really exist? Are they more akin to the infamous "file-like object" which is whatever it needs to be for the purpose at hand? Guido has since said that the ABCs are intended to be definitive, but the docs don't really make that clear either. (And the ABC doc page talks about "APIs", not "protocols"!) -- Greg