On Thu, May 14, 2020 at 09:47:36AM -0700, Andrew Barnert wrote:
On May 14, 2020, at 03:01, Steven D'Aprano
wrote: On Mon, May 11, 2020 at 10:41:06AM -0700, Andrew Barnert via Python-ideas wrote:
I think in general people will expect that a slice view on a sequence acts like “some kind of sequence”, not like the same kind they’re viewing—again, they won’t be surprised if you can’t insert into a slice of a list.
o_O
For nearly 30 years, We've been able to insert into a slice of a list. I'm going to be *really* surprise if that stops working
Which is exactly why Christopher said from the start of this thread, and everyone else has agreed at every step of the way, that we can’t change the default behavior of slicing, we have to instead add some new way to specifically ask for something different.
Which is why I was so surprised that you suddenly started talking about not being able to insert into a slice of a list rather than a view.
Not only that, but whatever gives you view-slicing must look sufficiently different that you notice the difference—and ideally that gives you something you can look up if you don’t know what it means. I think lst.view[10:20] fits that bill.
Have we forgotten how to look at prior art all of a sudden? Suddenly been possessed by the spirits of deceased Java and Ruby programmers intent on changing the look and feel of Python to make it "real object oriented"? *wink* We have prior art here: b'abcd'.memoryview # No, not this. memoryview(b'abcd') # That's the one. 'abcd'.iter # No, not that either. iter('abcd') # That's it. In fairness, I do have to point out that dict views do use a method interface, but: 1. Dict views came with a lot of backwards-compatibility baggage; they were initially methods that returned lists; then methods that returned iterators were added, then methods that returned views were added, and finally in 3.x the view methods were renamed and the other six methods were removed. 2. There is only a single builtin mapping object, dict, not like sequences where there are lists, tuples, range objects, strings, byte strings and bytearrays. 3. Dicts need three kinds of view, keys/items/values, not just one; adding three new builtin functions just for dicts is perhaps a bit excessive. So if we're to add a generic sequence view object, none of those factors are relevent: 1. No backwards-compatibility baggage; we can pick the interface which is the most Pythonic. That's a protocol based on a dunder, not a method. 2. At least six builtins, not one. 3. Only one kind of sequence view, not three. -- Steven