Title: Language reference is ambiguous regarding next() method lookup
Type: behavior Stage:
Components: Documentation Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: georg.brandl, ncoghlan, terry.reedy
Priority: normal Keywords:

Created on 2009-04-12 00:58 by ncoghlan, last changed 2019-03-15 22:55 by BreamoreBoy.

Messages (5)
msg85883 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-12 00:58
The language reference is currently silent as to whether or not an
iterator's next() method is looked up on every pass around a for loop,
or whether it is OK for an implementation to look the method up once at
the start of the loop, cache the result and call it again each time
around the loop without doing the lookup again.

The language reference should require implementations to follow
CPython's behaviour in this respect: the method should be looked up
again on each pass around the loop.

As per this email on python-ideas:
msg86104 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-04-18 06:55
I was surprised when this came up with another issue.
Why does  CPython behave that way?  Accident or justified decision?
msg86113 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2009-04-18 11:33
Guido didn't actually say whether or not this was originally just an
implementation accident or a deliberate design choice - he just
indicated that this was a case where caching the bound method should be
disallowed because it could change the semantics of existing programs.
msg236179 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2015-02-18 15:54
Thrown up by selecting "Random Issue", if nothing else it looks to me as if __next__ is missing from and so should be documented in
msg236187 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-02-18 18:12
Still true in the current doc
object.__iter__ in listed in 3.3.6. Emulating container types
A listing for __next__ could follow that.

Both iterator special methods are documented in
Date User Action Args
2019-03-15 22:55:14BreamoreBoysetnosy: - BreamoreBoy
2015-02-18 18:12:38terry.reedysetmessages: + msg236187
2015-02-18 15:54:02BreamoreBoysetnosy: + BreamoreBoy
messages: + msg236179
2010-10-29 10:07:21adminsetassignee: georg.brandl -> docs@python
2009-04-18 11:33:19ncoghlansetmessages: + msg86113
2009-04-18 06:55:12terry.reedysetnosy: + terry.reedy
messages: + msg86104
2009-04-12 00:58:26ncoghlancreate