On Mon, Nov 29, 2021 at 4:13 PM David Mertz, Ph.D.
wrote:
>
> Or anyway, what would you call `bar := Bar()` if not "an iterator?!
>
A "broken iterator".
ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
There was just a bpo on this — discussion of exactly what an Iterable th
or is.
I’m pretty sure the conclusion was that in order to be an Iterator, an
object needs to have __iter_. I’m not totally sure that it has to return
self, but that is the expected behavior, so that it can be re-entrant.
On Mon, Nov 29, 2021, 12:33 AM Paul Bryan wrote:
> 1. Noted: Python's for statement will happily iterate over an object that
> only implements __next__.
> 2. The documentation is pretty clear on what is expected of an iterator:
> implement __next__ *and* __iter__.
> 3. It is perfectly reasonable
1. Noted: Python's for statement will happily iterate over an object
that only implements __next__.
2. The documentation is pretty clear on what is expected of an
iterator: implement __next__ and __iter__.
3. It is perfectly reasonable for __iter__ to return something other
than self; the
On Mon, Nov 29, 2021, 12:16 AM Paul Bryan wrote:
> And the second link?
>
Same comments, basically. But the more germane thing is that even assuming
a class has both .__next__() and .__iter__(), it is perfectly reasonable
for the latter to return something other than `self`.
The Foo and Bar
And the second link?
On Mon, 2021-11-29 at 00:11 -0500, David Mertz, Ph.D. wrote:
> On Sun, Nov 28, 2021, 11:43 PM Paul Bryan wrote:
> > According to https://docs.python.org/3/glossary.html#term-iterator
> > and https://docs.python.org/3/library/stdtypes.html#typeiter,
> > iterators must
On Sun, Nov 28, 2021, 11:43 PM Paul Bryan wrote:
> According to https://docs.python.org/3/glossary.html#term-iterator and
> https://docs.python.org/3/library/stdtypes.html#typeiter, iterators must
> implement the __iter__ method.
>From your first link:
CPython implementation detail: CPython
According
to https://docs.python.org/3/glossary.html#term-iterator and
https://docs.python.org/3/library/stdtypes.html#typeiter,
iterators must implement the __iter__ method.
On Sun, 2021-11-28 at 22:02 -0500, David Mertz, Ph.D. wrote:
> On Sun, Nov 28, 2021, 8:59 PM Steven D'Aprano
> > To be
On Sun, Nov 28, 2021, 8:59 PM Steven D'Aprano
> To be an iterator, your object needs:
>
> 1. a `__next__` method which returns the next value;
> 2. and an `__iter__` method which returns self.
>
That's not quite right.
An iterator only needs .__next__(), and an iterable only needs .__iter__().
On Sun, Nov 28, 2021, 7:49 PM Christopher Barker
> One example was a proposal a while back on this list for a "groupby" in
> itertools (it kind of withered on the vine, like many good ideas here), I
> suggested that it be made comprehension friendly, and some others including
> the OP) didn't see
On Sun, Nov 28, 2021 at 04:48:01PM -0800, Christopher Barker wrote:
> One example was a proposal a while back on this list for a "groupby" in
> itertools (it kind of withered on the vine, like many good ideas here), I
> suggested that it be made comprehension friendly, and some others including
>
On Sun, Nov 28, 2021 at 10:52:03AM -0800, Christopher Barker wrote:
> Back in the day Python had map, filter, and reduce.
And still does :-)
> Then comprehensions were added, which are another way to express map and
> filter in one go.
>
> I really like comprehensions.
>
> But since then,
On Sun, Nov 28, 2021 at 04:40:15PM -0800, Christopher Barker wrote:
> Sure, but I"m not sure it's THAT much harder to say:
>
> If you want to make an iterator, define a __next__ method.
Just for the record, that's not what makes an iterator. That makes a
half-and-half something almost but not
On Sun, Nov 28, 2021 at 11:14 AM Chris Angelico wrote:
> On Mon, Nov 29, 2021 at 5:54 AM Christopher Barker
> wrote:
> > Back in the day Python had map, filter, and reduce.
> >
> > Then comprehensions were added, which are another way to express map and
> filter in one go.
> >
> > I really like
On Sun, Nov 28, 2021 at 11:28 AM Chris Angelico wrote:
> On Mon, Nov 29, 2021 at 6:01 AM Christopher Barker
> wrote:
>
> > But we *could* define a new ChainedIterator ABC. Anyone could then
> subclass from it to get the chaining behavior, and we could (potentially)
> use it for many of the
Hi Evpok,
Evpok Padding wrote:
> Hi,
> All apologies if it has been clarified earlier, but if you dislike nested
> method calls what is wrong with operating on generators as in
No worries! I think the theme of this discussion is using idioms
from map, reduce + functions from itertools module
> On 26 Nov 2021, at 16:00, eyalgr...@gmail.com wrote:
>
> i wonder whether:
>
> from myutils import myprint as print
>
> or
>
> _print = print
> print = myprint
>
> is really the pythonic way?
The problem with this is that there are more ways to output then the print
command.
Only
On Mon, Nov 29, 2021 at 6:01 AM Christopher Barker wrote:
> Hmm -- I jsut had a whacky idea:
>
> As pointed out, adding a bunch of chaining methods to the Iterator ABC isn't
> really helpful, as it would A) potentially break / override existing classes
> that happen to use teh same names, and
On Mon, Nov 29, 2021 at 5:54 AM Christopher Barker wrote:
>
> On Sun, Nov 28, 2021 at 9:30 AM Evpok Padding wrote:
>>
>> All apologies if it has been clarified earlier, but if you dislike nested
>> method calls what is wrong with operating on generators as in
>>
>> ```pycon
>> >>> itr = (i**2
On Sun, Nov 28, 2021 at 3:06 AM Stephen J. Turnbull <
stephenjturnb...@gmail.com> wrote:
> Chris Angelico writes:
>
> > The policy of not returning self is, from my understanding, to clarify
> > which methods return a new thing and which mutate the existing one
yup.
> Which is what I would
On Sun, Nov 28, 2021 at 9:30 AM Evpok Padding
wrote:
> All apologies if it has been clarified earlier, but if you dislike nested
> method calls what is wrong with operating on generators as in
>
> ```pycon
> >>> itr = (i**2 for i in range(8))
> >>> itr = (i-1 for i in itr if i > 0)
> >>>
Hi,
All apologies if it has been clarified earlier, but if you dislike nested
method calls what is wrong with operating on generators as in
```pycon
>>> itr = (i**2 for i in range(8))
>>> itr = (i-1 for i in itr if i > 0)
>>> list(itr)
[0, 3, 8, 15, 24, 35, 48]
```
This covers chains of maps
Hi Stephen,
Stephen J. Turnbull wrote:
> 1. Is dataflow/fluent programming distinguishable from whatever it
> was that Guido didn't like about method chaining idioms? If so,
> how?
Are you referring to this
https://mail.python.org/pipermail/python-dev/2003-October/038855.html?
He
Chris Angelico writes:
> The policy of not returning self is, from my understanding, to clarify
> which methods return a new thing and which mutate the existing one. It
> makes this sort of distinction very obvious:
That seems likely.
> If list.sort() returned self after mutation, the
24 matches
Mail list logo