On Thu, Dec 13, 2018 at 06:53:54PM +1300, Greg Ewing wrote:
> In any case, I don't claim that my MapView implements the full
> iterator protocol, only enough of it to pass for an iterator in
> most likely scenarios that assume one.
Whether your hybrid sequence+iterator is close enough to an
On Thu, 13 Dec 2018 at 05:55, Greg Ewing wrote:
>
> Chris Angelico wrote:
> > On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
> > Python-ideas wrote:
> >
> > obj is iter(obj)
> >>
> >>Is that a hard and fast rule?
> > Yes, it is.
> >
> >
On Thu, Dec 13, 2018 at 4:54 PM Greg Ewing wrote:
>
> Chris Angelico wrote:
> > On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
> > Python-ideas wrote:
> >
> > obj is iter(obj)
> >>
> >>Is that a hard and fast rule?
> > Yes, it is.
> >
> >
Chris Angelico wrote:
On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
Python-ideas wrote:
obj is iter(obj)
Is that a hard and fast rule?
Yes, it is.
https://docs.python.org/3/library/stdtypes.html#iterator-types
The docs aren't very clear on this point. They claim this
On Wed, Dec 12, 2018 at 08:06:17PM -0800, Chris Barker - NOAA Federal wrote:
> >>> and the test for an iterator is:
> >>>
> >>> obj is iter(obj)
>
> Is that a hard and fast rule?
Yes, that's the rule for the iterator protocol.
Any object can have an __iter__ method which returns anything you
On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
Python-ideas wrote:
>
> >>> and the test for an iterator is:
> >>>
> >>> obj is iter(obj)
>
> Is that a hard and fast rule? I know it’s the vast majority of cases,
> but I imagine you could make an object that behaved exactly like
>>> and the test for an iterator is:
>>>
>>> obj is iter(obj)
Is that a hard and fast rule? I know it’s the vast majority of cases,
but I imagine you could make an object that behaved exactly like an
iterator, but returned some proxy object rather that itself.
Not sure why one would do that,
On Wed, Dec 12, 2018 at 12:50:41PM +1300, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >The iterator protocol is that iterators must:
> >
> >- have a __next__ method;
> >- have an __iter__ method which returns self;
> >
> >and the test for an iterator is:
> >
> >obj is iter(obj)
>
> By that
On 12/11/2018 6:50 PM, Greg Ewing wrote:
I'm not necessarily saying this *should* be done, just pointing
out that it's a possible strategy for migrating map() from
an iterator to a view, if we want to do that.
Python has list and list_iterator, tuple and tuple_iterator, set and
set_iterator,
On Wed, Dec 12, 2018 at 11:31:03AM +1300, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >I suggest we provide a separate mapview() type that offers only the lazy
> >sequence API, without trying to be an iterator at the same time.
>
> Then we would be back to the bad old days of having two
Steven D'Aprano wrote:
The iterator protocol is that iterators must:
- have a __next__ method;
- have an __iter__ method which returns self;
and the test for an iterator is:
obj is iter(obj)
By that test, it identifies as a sequence, as does testing it
for the presence of __len__:
>>>
On Tue, Dec 11, 2018 at 11:10 AM Terry Reedy wrote:
> > I _think_ someone may be advocating that map() could return an
> > iterable if it is passed a iterable,
>
> I believe you mean 'iterator' rather than 'iterable' here and below as a
> sequence is an iterable.
>
well, the iterator / iterable
Steven D'Aprano wrote:
I suggest we provide a separate mapview() type that offers only the lazy
sequence API, without trying to be an iterator at the same time.
Then we would be back to the bad old days of having two functions
that do almost exactly the same thing. My suggestion was made in
On 12/11/2018 12:01 PM, Chris Barker - NOAA Federal via Python-ideas wrote:
Perhaps I got confused by the early part of this discussion.
My point was that there is no “map-like” object at the Python level.
(That is no Map abc).
Py2’s map produced a sequence. Py3’s map produced an iterable.
So
On 12/11/2018 6:48 AM, E. Madison Bray wrote:
The idea would be to now enhance the existing built-ins to restore at
least some previously lost assumptions, at least in the relevant
cases. To give an analogy, Python 3.0 replaced range() with
(effectively) xrange(). This broken a lot of
On 12/1/2018 8:07 PM, Greg Ewing wrote:
Steven D'Aprano wrote:
After defining a separate iterable mapview sequence class
For backwards compatibilty reasons, we can't just make map() work like
this, because that's a change in behaviour.
Actually, I think it's possible to get the best of
Perhaps I got confused by the early part of this discussion.
My point was that there is no “map-like” object at the Python level.
(That is no Map abc).
Py2’s map produced a sequence. Py3’s map produced an iterable.
So any API that was expecting a sequence could accept the result of a
py2 map,
On Tue, Dec 11, 2018 at 12:48:10PM +0100, E. Madison Bray wrote:
> Right now I'm specifically responding to the sub-thread that Greg
> started "Suggested MapView object", so I'm considering this a mostly
> clean slate from the previous thread "__len__() for map()". Different
> ideas have been
On Mon, Dec 10, 2018 at 05:15:36PM -0800, Chris Barker via Python-ideas wrote:
[...]
> I'm still confused -- what's so wrong with:
>
> list(map(func, some_iterable))
>
> if you need a sequence?
You might need a sequence. Why do you think that has to be an *eager*
sequence?
I can think of two
On Tue, 11 Dec 2018 at 11:49, E. Madison Bray wrote:
> The idea would be to now enhance the existing built-ins to restore at
> least some previously lost assumptions, at least in the relevant
> cases. To give an analogy, Python 3.0 replaced range() with
> (effectively) xrange(). This broken a
On Tue, Dec 11, 2018 at 12:13 PM Paul Moore wrote:
>
> On Tue, 11 Dec 2018 at 10:38, E. Madison Bray wrote:
> > I don't understand why this is confusing.
> [...]
> > For something like a fixed sequence a "map" could just as easily be
> > defined as a pair (, ) that applies ,
> > which I'm
On Tue, 11 Dec 2018 at 10:38, E. Madison Bray wrote:
> I don't understand why this is confusing.
[...]
> For something like a fixed sequence a "map" could just as easily be
> defined as a pair (, ) that applies ,
> which I'm claiming is a pure function, to every element returned by
> the . This
On Tue, Dec 11, 2018 at 2:16 AM Chris Barker wrote:
> On Mon, Dec 10, 2018 at 5:23 AM E. Madison Bray wrote:
>>
>> Indeed; I believe it is very useful to have a map-like object that is
>> effectively an augmented list/sequence.
>
>
> but what IS a "map-like object" -- I'm trying to imagine what
On Mon, Dec 10, 2018 at 5:23 AM E. Madison Bray
wrote:
> Indeed; I believe it is very useful to have a map-like object that is
> effectively an augmented list/sequence.
but what IS a "map-like object" -- I'm trying to imagine what that actually
means.
"map" takes a function and maps it onto a
On Sun, Dec 2, 2018 at 11:52 PM Greg Ewing wrote:
>
> Steven D'Aprano wrote:
> > Perhaps more like the principle of most
> > astonishment: the object changes from sized to unsized even if you don't
> > modify its value or its type, but merely if you look at it the wrong
> > way:
>
> Yes, but keep
Steven D'Aprano wrote:
Perhaps more like the principle of most
astonishment: the object changes from sized to unsized even if you don't
modify its value or its type, but merely if you look at it the wrong
way:
Yes, but keep in mind the purpose of the whole thing is to
provide a sequence
On Mon, Dec 03, 2018 at 02:04:31AM +1300, Greg Ewing wrote:
> Chris Angelico wrote:
> >I can't help thinking that it will be extremely surprising to have the
> >length remain the same while the items get consumed.
>
> That can be fixed. The following version raises an exception if
> you try to
Chris Angelico wrote:
I can't help thinking that it will be extremely surprising to have the
length remain the same while the items get consumed.
That can be fixed. The following version raises an exception if
you try to find the length after having used it as an iterator.
(I also fixed a bug
On Sun, Dec 2, 2018 at 12:08 PM Greg Ewing wrote:
> class MapView:
> def __len__(self):
> return min(map(len, self.args))
>
> def __iter__(self):
> return self
>
> def __next__(self):
> if not self.iterator:
> self.iterator = map(self.func,
29 matches
Mail list logo