On May 14, 2020, at 11:53, Ricky Teachey firstname.lastname@example.org wrote:
So that means a view() function (with maybe a different name) -- however, that brings up the issue of where to put it. I'm not sure that it warrants being in builtins, but where does it belong? Maybe the collections module? And I really think the extra import would be a barrier.
It occurs to me-- and please quickly shut me down if this is a really dumb idea, I won't be offended-- `memoryview` is already a top-level built-in. I know it has a near completely different meaning with regards to bytes objects than we are talking about with a sequence view object. But could it do double duty as a creator of views for sequences, too?
But bytes and bytearray are Sequences, and maybe other things that support the buffer protocol are too.
At first glance, it sounds terrible that the same function gives you a locking buffer view for some sequences and an indirect regular sequence view for others, and that there’s no way to get the latter for bytes even when you explicitly want that. But maybe in practice it wouldn’t be nearly as bad as it sounds? I don’t know. It sounds terrible in theory that NumPy arrays are almost but not quite Sequences, but in practice I rarely get confused by that. Maybe the same would be true here?
There’s also the problem that “memoryview” is kind of a misleading name if you apply it to, say, a range instead of a list. But again, I’m not sure how bad that would be in practice.