On Thu, May 7, 2020 at 1:26 AM Christopher Barker <pythonchb@gmail.com> wrote:
But wait a minute, zip isn't just a "callable", it's a class, and adding more methods to it seems perfectly natural, just like lots of other built-in classes.
Zip is a class in CPython 3.8. it may or may not be in other implementations or versions. The API users are currently promised says nothing about it needing to be implemented as a class.
and it was a function in 2.7. a zip instance on the other hand, returns an iterable, that does not provide any other methods or uses. I have to say, I have not idea why zip is a class rather than a function that returns a zip_iterator instance, but it is certainly an implementation detail.
It seems common in all the utility "functions" that make iterators. I haven't tried everything, but for example:
type(map), type(filter), type(itertools.count), type(itertools.product) (<class 'type'>, <class 'type'>, <class 'type'>, <class 'type'>)
But I didn't know those until I looked... and I don't HAVE TO know for any practical use of them. As Chris notes, it's an implementation detail, subject to change. -- The dead increasingly dominate and strangle both the living and the not-yet born. Vampiric capital and undead corporate persons abuse the lives and control the thoughts of homo faber. Ideas, once born, become abortifacients against new conceptions.