[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Guido van Rossum
On Tue, Sep 14, 2021 at 9:31 PM Steven D'Aprano wrote: > If it helps, I have tons of code that tests for iterators using: > > iter(obj) is obj > > That has been a documented requirement for the iterator protocol > forever. Its in the PEP. > > "A class that wants to be an iterator should

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Guido van Rossum
On Tue, Sep 14, 2021 at 9:03 PM Steven D'Aprano wrote: > On Tue, Sep 14, 2021 at 12:33:32PM -0700, Guido van Rossum wrote: > > My view of this is: > > > > A. It's not an iterator if it doesn't define `__next__`. > > > > B. It is strongly recommended that iterators also define `__iter__`. > > > >

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Steven D'Aprano
If it helps, I have tons of code that tests for iterators using: iter(obj) is obj That has been a documented requirement for the iterator protocol forever. Its in the PEP. "A class that wants to be an iterator should implement two methods: a next() method that behaves as described above,

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Steven D'Aprano
On Tue, Sep 14, 2021 at 12:33:32PM -0700, Guido van Rossum wrote: > My view of this is: > > A. It's not an iterator if it doesn't define `__next__`. > > B. It is strongly recommended that iterators also define `__iter__`. > > In "standards" language, I think (A) is MUST and (B) is merely OUGHT

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Brandt Bucher
Guido van Rossum wrote: > TBH I don't think there is an *actual* problem here. I think it's just > about choosing the right wording for the glossary (which IMO does not have > status as a source of truth anyway). Good point. I'm probably approaching this from the wrong angle (by trying to "fix"

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Guido van Rossum
On Tue, Sep 14, 2021 at 4:33 PM Brandt Bucher wrote: > Guido van Rossum wrote: > > On Tue, Sep 14, 2021 at 3:49 PM Brandt Bucher brandtbuc...@gmail.com > > wrote: > > > I think it's also worth noting that a missing "`__iter__` that returns > > > self" is trivial to recover from... just use a new

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Brandt Bucher
Guido van Rossum wrote: > On Tue, Sep 14, 2021 at 3:49 PM Brandt Bucher brandtbuc...@gmail.com > wrote: > > I think it's also worth noting that a missing "`__iter__` that returns > > self" is trivial to recover from... just use a new reference to the > > iterator instead. The overhead of a method

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Guido van Rossum
On Tue, Sep 14, 2021 at 3:49 PM Brandt Bucher wrote: > I think it's also worth noting that a missing "`__iter__` that returns > self" is trivial to recover from... just use a new reference to the > iterator instead. The overhead of a method call for this convention almost > seems silly. > The

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Brandt Bucher
I think it's also worth noting that a missing "`__iter__` that returns self" is trivial to recover from... just use a new reference to the iterator instead. The overhead of a method call for this convention almost seems silly. What worries me most about changing the current "requirement" is

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Patrick Reader
I think there is also a distinction about the *current* meaning of "required" to be made, in "[i]terators are required to have an |__iter__()| method": "required" doesn't specify whether this is: 1. by convention, and doing

[Python-Dev] Re: Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Guido van Rossum
My view of this is: A. It's not an iterator if it doesn't define `__next__`. B. It is strongly recommended that iterators also define `__iter__`. In "standards" language, I think (A) is MUST and (B) is merely OUGHT or maybe SHOULD. On Tue, Sep 14, 2021 at 12:30 PM Brett Cannon wrote: > Over

[Python-Dev] Should the definition of an "(async) iterator" include __iter__?

2021-09-14 Thread Brett Cannon
Over in https://github.com/python/typeshed/issues/6030 I have managed to kick up a discussion over what exactly an "iterator" is. If you look at https://docs.python.org/3/library/functions.html#iter you will see the docs say it "Return[s] an iterator

[Python-Dev] Re: PEP 467 feedback from the Steering Council

2021-09-14 Thread Baptiste Carvello
Le 13/09/2021 à 19:01, Barry Warsaw a écrit : > There is some discussion going on in bpo-45155 about what the default value > of the `byteorder` argument should be for int.to_bytes() and int.from_bytes(): Hello, a use case and feature request: I have used int.to_bytes() and int.from_bytes()