Please take into account that
len(a)
isn’t necessarily needed forlist(a)
, is it?
If the __len__
is there, Python reasonably assumes the length is known, and uses it. This enables a much faster allocation of a known finite amount of memory on the stack, instead of consuming the entire iterator, then copying it all afterwards to the memory region only once it can be allocated in bulk, or having to construct the list machinery around the cached iterator items on the fly only as they’re yielded.
Python should not compromise performance (in construction of a fundamental data structure) for the edge case of an method implementation, that returns NotImplemented.
Use one of my two work arounds, just don’t implement the method at all, or make it an abstract method.