On 2020-12-29 15:01, Christopher Barker wrote:
along with a COMPLETE list of the language features that make use of that protocol.
That is pretty much impossible -- that's kind of the point of a protocol -- it can be used in arbitrary places in arbitrary code. would you expect a COMPLETE list of all the language features that use the iteration protocol?
Yes, but perhaps not as complete as you thought I meant. :-) What I mean by "language features" here is basically syntactic features that IMPLICITLY invoke the protocol. Certainly arbitrary code can use a protocol the sense that any function can call some other function that eventually winds up using the protocol. Also, code can explicitly invoke the iterator protocol, by, e.g., calling obj.__next__(), but that's not a problem because you can easily look up how the object defines __next__. The magic part is when you have something like `for x in obj`, which includes not even any indirect references (i.e., in called functions) to `__iter__` or `__next__`, yet winds up calling them. And it's because that is magic that we need to make it very explicit. So by a complete list of language features that use iteration I would mean. . . well, this is why we need to do this, to make sure we get them all! :-) But the idea is that all usages of the iterator protocol should funnel through a small number of entrypoints --- that's the point of a protocol, in some sense. So the list would be: `for` (including comprehensions), the builtin functions `next` and `iter` because they're sort of a manual crank of the protocol. . . is there anything else? Maybe `yield` because it implicitly creates objects that implement the protocol? That's the kind of "complete list" I mean. I'm not including things like library functions that happen to iterate over stuff. The whole point of the iterator protocol is that it defines iteration, so every such function can say "this function iterates over obj" (with a link to the protocol!) and that's enough. But cases where syntax implicitly invokes the protocol, those are the ones that must be exhaustively listed. -- Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown