This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Language reference is ambiguous regarding next() method lookup
Type: behavior Stage:
Components: Documentation Versions:
process
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 2022-04-11 14:56 by admin.

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:
http://mail.python.org/pipermail/python-ideas/2009-April/004083.html
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 https://docs.python.org/3.1/reference/datamodel.html#special-method-names
msg236187 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-02-18 18:12
Still true in the current doc
https://docs.python.org/3/reference/datamodel.html#special-method-names
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
https://docs.python.org/3/library/stdtypes.html#iterator-types
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49989
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