Skip to content

Conversation

@PeterJCLaw
Copy link
Contributor

Summary

This appears to have been a copy/paste error from the list example, as the subscript is not present in the original next/iter example only in the case where the error case is shown. While in the specific example code the subscript actually has no effect, it does make the example slightly confusing.

Consider the following variations, first the example from the docs unchanged and second the same code but not hitting the intended error case (due to using a non-empty collection):

$ python3 -c 'next(iter(range(0)))[0]'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
StopIteration

$ python3 -c 'next(iter(range(1)))[0]'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'int' object is not subscriptable

Test Plan

Not directly tested, however see inline snippets above.

This appears to have been a copy/paste error from the list example,
as the subscript is not present in the original next/iter example
only in the case where the error case is shown. While in the
specific example code the subscript actually has no effect, it
does make the example slightly confusing.

Consider the following variations, first the example from the docs
unchanged and second the same code but not hitting the intended
error case (due to using a non-empty collection):
```console
$ python3 -c 'next(iter(range(0)))[0]'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
StopIteration

$ python3 -c 'next(iter(range(1)))[0]'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'int' object is not subscriptable
```
@PeterJCLaw PeterJCLaw marked this pull request as ready for review December 20, 2025 21:15
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ntBre ntBre added the documentation Improvements or additions to documentation label Dec 22, 2025
@ntBre ntBre merged commit 87406b4 into astral-sh:main Dec 22, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants