[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-17 Thread Stephen J. Turnbull
Steven D'Aprano writes: > [Aside: despite what the Zen says, I think *protocols* are far more > important to Python than *namespaces*.] I think you misread the Zen. :-) That-is-my-opinion-I-do-not-however-speak-for-its-author-ly y'rs, ___ Python-ide

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-16 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 21:35, Steven D'Aprano wrote: > > On Fri, May 15, 2020 at 05:44:59PM -0700, Andrew Barnert wrote: > >> Once you go with a separate view-creating function (or type), do we even >> need the dunder? > > Possibly not. But the beauty of a protocol is that it can work even if >

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-16 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 21:25, Steven D'Aprano wrote: > > On Fri, May 15, 2020 at 01:00:09PM -0700, Christopher Barker wrote: > >> I know you winked there, but frankly, there isn't a clear most Pythonic API >> here. Surely you do'nt think PYhton should have no methods? > > That's not what I said.

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 05:44:59PM -0700, Andrew Barnert wrote: > Once you go with a separate view-creating function (or type), do we even need > the dunder? Possibly not. But the beauty of a protocol is that it can work even if the object doesn't define a `__view__` dunder. - If the object de

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 01:00:09PM -0700, Christopher Barker wrote: > I know you winked there, but frankly, there isn't a clear most Pythonic API > here. Surely you do'nt think PYhton should have no methods? That's not what I said. Of course Python should have methods -- it's an OOP language aft

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 18:21, Christopher Barker wrote: > > Hmm, more thought needed. Speaking of “more thought needed”, I took a first pass over cleaning up my quick&dirty slice view class and adding the slicer class, and found some bikesheddable options. I think in most cases the best answer is

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 18:21, Christopher Barker wrote: > >> On Fri, May 15, 2020 at 5:45 PM Andrew Barnert wrote: > >> On May 15, 2020, at 13:03, Christopher Barker wrote: >> > >> > Taking all that into account, if we want to add "something" to Sequence >> > behavior (in this case a sequence_v

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Christopher Barker
On Fri, May 15, 2020 at 5:45 PM Andrew Barnert wrote: > On May 15, 2020, at 13:03, Christopher Barker wrote: > > > > Taking all that into account, if we want to add "something" to Sequence > behavior (in this case a sequence_view object), then adding a dunder is > really the only option -- you'd

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 13:03, Christopher Barker wrote: > > Taking all that into account, if we want to add "something" to Sequence > behavior (in this case a sequence_view object), then adding a dunder is > really the only option -- you'd need a really compelling reason to add a > Sequence metho

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 03:50, Steven D'Aprano wrote: > > On Thu, May 14, 2020 at 09:47:36AM -0700, Andrew Barnert wrote: >>> On May 14, 2020, at 03:01, Steven D'Aprano wrote: >>> >> Which is exactly why Christopher said from the start of this thread, >> and everyone else has agreed at every step

[Python-ideas] Re: Adding slice Iterator to Sequences

2020-05-15 Thread Christopher Barker
A > > different method/property/class/function that gives you iterators > > would be fine. > > We already have such. It's called itertools.islice(). > If you had read the proposal, you’d know that was brought up, obviously. I'm sorry, but you're missing the point here. You and Christopher see

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Christopher Barker
TL;DR: no need to come to consensus about the most "Pythonic" API for a sequence view -- due to potential name clashes, adding a dunder is pretty much the only option. Details below: On Fri, May 15, 2020 at 3:50 AM Steven D'Aprano wrote: > I think lst.view[10:20] fits that bill. > > Have we fo

[Python-ideas] Re: Adding slice Iterator to Sequences

2020-05-15 Thread Rhodri James
On 14/05/2020 19:56, Andrew Barnert wrote: On May 14, 2020, at 10:45, Rhodri James wrote: On 14/05/2020 17:47, Andrew Barnert via Python-ideas wrote: 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

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
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 > >>

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Andrew Barnert via Python-ideas
On May 14, 2020, at 11:53, Ricky Teachey 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 re

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Andrew Barnert via Python-ideas
On May 14, 2020, at 10:45, Rhodri James wrote: > > On 14/05/2020 17:47, Andrew Barnert via Python-ideas wrote: >> 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

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Ricky Teachey
> > 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 oc

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Andrew Barnert via Python-ideas
On May 14, 2020, at 03:35, Steven D'Aprano wrote: > > On Sun, May 10, 2020 at 09:36:14PM -0700, Andrew Barnert via Python-ideas > wrote: > > >>> for i in itertools.seq_view(a_list)[::2]: >>>... >>> >>> I still think I prefer this though: >>> >>> for i in a_list.view[::2]: >>>... >

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Rhodri James
On 14/05/2020 17:47, Andrew Barnert via Python-ideas wrote: 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

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Andrew Barnert via Python-ideas
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—

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Christopher Barker
On Thu, May 14, 2020 at 3:32 AM Steven D'Aprano wrote: > On Sun, May 10, 2020 at 09:36:14PM -0700, Andrew Barnert via Python-ideas > wrote: > > > for i in itertools.seq_view(a_list)[::2]: > > > ... > > > > > > I still think I prefer this though: > > > > > > for i in a_list.view[::2]: > > > Ag

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Christopher Barker
On Thu, May 14, 2020 at 2:58 AM 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

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Steven D'Aprano
On Sun, May 10, 2020 at 09:36:14PM -0700, Andrew Barnert via Python-ideas wrote: > > for i in itertools.seq_view(a_list)[::2]: > > ... > > > > I still think I prefer this though: > > > > for i in a_list.view[::2]: > > ... > > Agreed. A property on sequences would be best, Why? This

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-14 Thread Steven D'Aprano
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 > slic

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-11 Thread Christopher Barker
On Mon, May 11, 2020 at 11:38 AM Andrew Barnert wrote: > On May 11, 2020, at 10:57, Alex Hall wrote: > >  > On Mon, May 11, 2020 at 12:50 AM Christopher Barker > wrote: > > >> Though it is heading in a different direction that where Andrew was >> proposing, that this would be about making and

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-11 Thread Andrew Barnert via Python-ideas
On May 11, 2020, at 10:57, Alex Hall wrote: > >  >> On Mon, May 11, 2020 at 12:50 AM Christopher Barker >> wrote: > > >> Though it is heading in a different direction that where Andrew was >> proposing, that this would be about making and using views on sequences, >> which really wouldn't

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-11 Thread Alex Hall
On Mon, May 11, 2020 at 12:50 AM Christopher Barker wrote: > I'm still confused what you mean by extend to all iterators? you mean that > you could use slice syntax with anything iterable> > > And where does this fit in to the iterable vs iterator continuum? > > iterables will return an iterator

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-11 Thread Andrew Barnert via Python-ideas
On May 10, 2020, at 21:51, Christopher Barker wrote: > >  > On Sun, May 10, 2020 at 9:36 PM Andrew Barnert wrote: > >> However, there is one potential problem with the property I hadn’t thought >> of until just now: I think people will understand that mylist.view[2:] is >> not mutable, but w

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Ricky Teachey
On Mon, May 11, 2020 at 1:52 AM Ricky Teachey wrote: > I have nothing particularly useful to add, only that this is potentially a > really fantastic idea with a lot of promise, IMO. > > It would be nice to have some view objects with a lot of > functionality that can be sliced not only for effici

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Ricky Teachey
I have nothing particularly useful to add, only that this is potentially a really fantastic idea with a lot of promise, IMO. It would be nice to have some view objects with a lot of functionality that can be sliced not only for efficiency, but for other purposes. One might be (note that below I am

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Christopher Barker
On Sun, May 10, 2020 at 9:36 PM Andrew Barnert wrote: Here is where I think you (Andrew) and I (Chris B.) differ in our goals. My >> goal here is to have an easily accessible way to use the slice syntax to >> get an iterable that does not make a copy. >> > > It’s just a small difference in emp

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Andrew Barnert via Python-ideas
On May 10, 2020, at 15:39, Christopher Barker wrote: > >  >> On Sun, May 10, 2020 at 12:48 PM Andrew Barnert wrote: > >> Is there any way you can fix the reply quoting on your mail client, or >> manually work around it? > > I'm trying -- sorry I've missed a few. It seems more and more "moder

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Christopher Barker
On Sat, May 9, 2020 at 1:58 PM Alex Hall wrote: > > https://github.com/PythonCHB/islice-pep/blob/master/pep-xxx-islice.rst >> >> And the prototype implementation: >> >> https://github.com/PythonCHB/islice-pep/blob/master/islice.py >> > > I think this is a good idea. For sequences I'm not sure ho

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Christopher Barker
On Sun, May 10, 2020 at 12:48 PM Andrew Barnert wrote: > Is there any way you can fix the reply quoting on your mail client, or > manually work around it? > I'm trying -- sorry I've missed a few. It seems more and more "modern" email clients make "interspersed" posting really hard. But I hate bo

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Andrew Barnert via Python-ideas
On May 10, 2020, at 11:09, Christopher Barker wrote: Is there any way you can fix the reply quoting on your mail client, or manually work around it? I keep reading paragraphs and saying “why is he saying the same thing I said” only to realize that you’re not, that’s just a quote from me that i

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Alex Hall
On Sun, May 10, 2020 at 8:20 PM Andrew Barnert wrote: > On May 10, 2020, at 02:42, Alex Hall wrote: > > > > - Handling negative indices for sequences (is there any reason we don't > have that now?) > > Presumably partly just to keep it minimal and simple. Itertools is all > about transforming it

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Andrew Barnert via Python-ideas
On May 10, 2020, at 02:42, Alex Hall wrote: > > - Handling negative indices for sequences (is there any reason we don't have > that now?) Presumably partly just to keep it minimal and simple. Itertools is all about transforming iterables into other iterables in as generic a way as possible. N

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Christopher Barker
On Sat, May 9, 2020 at 9:11 PM Andrew Barnert wrote: > I don’t think it invalidates the basic idea at all, just that it suggests the design should be different. Originally, dict returned lists for keys, values, and items. In 2.2, iterator variants were added. In 3.0, the list and iterator varian

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-10 Thread Alex Hall
On Sun, May 10, 2020 at 5:00 AM Christopher Barker wrote: > On Sat, May 9, 2020 at 1:58 PM Alex Hall wrote: > >> I think this is a good idea. For sequences I'm not sure how big the >> benefit is - I get that it's more efficient, but I rarely care that much, >> because most lists are small. Why

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Andrew Barnert via Python-ideas
On May 9, 2020, at 19:43, Christopher Barker wrote: > > On Sat, May 9, 2020 at 1:03 PM Andrew Barnert wrote: > > https://github.com/PythonCHB/islice-pep/blob/master/pep-xxx-islice.rst > > I haven’t read the whole thing yet, but one thing immediately jumped out at > me: > > > and methods on co

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Christopher Barker
On Sat, May 9, 2020 at 1:58 PM Alex Hall wrote: > I think this is a good idea. For sequences I'm not sure how big the > benefit is - I get that it's more efficient, but I rarely care that much, > because most lists are small. Why not extend the proposal to all iterators, > or at least common one

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Christopher Barker
On Sat, May 9, 2020 at 1:03 PM Andrew Barnert wrote: > https://github.com/PythonCHB/islice-pep/blob/master/pep-xxx-islice.rst I haven’t read the whole thing yet, but one thing immediately jumped out at me: > and methods on

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Alex Hall
On Sat, May 9, 2020 at 9:41 PM Christopher Barker wrote: > Funny you should bring this up. > > I've been meaning, for literally years, to propose not quite this, but > adding a "slice iterator" to the sequence protocol. > > (though note that one alternative is adding slice syntax to > itertools.i

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Ram Rachum
+1 I like this! I never considered this idea. It's a good combination of efficiency and elegance. On Sat, May 9, 2020 at 10:41 PM Christopher Barker wrote: > Funny you should bring this up. > > I've been meaning, for literally years, to propose not quite this, but > adding a "slice iterator" to

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Andrew Barnert via Python-ideas
On May 9, 2020, at 12:38, Christopher Barker wrote: > > https://github.com/PythonCHB/islice-pep/blob/master/pep-xxx-islice.rst I haven’t read the whole thing yet, but one thing immediately jumped out at me: > and methods on containers, such as dict.keys return iterators in Python 3, No they d