[New-bugs-announce] [issue40579] Second argument to iterator.next not described

Andrew Black report at bugs.python.org
Sat May 9 11:00:43 EDT 2020


New submission from Andrew Black <apblack at pdx.edu>:

The documentation for the built-in function next (which calls the __next__ method on an iterator) discusses its behavior when the iterator is exhausted.
It talks about the StopIteration exception.  However, it does not say anything about calling next with two arguments.  See the library documentation at https://docs.python.org/3/library/stdtypes.html#iterator-types

My impression was that the presence of the second argument would suppress the StopIteration exception; instead next would return the value of the second argument.  That is the way that list iterators behave, for example.  This behavior should be documented.

----------
assignee: docs at python
components: Documentation
messages: 368525
nosy: Andrew Black, docs at python
priority: normal
severity: normal
status: open
title: Second argument to iterator.next not described
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40579>
_______________________________________


More information about the New-bugs-announce mailing list