8000 [3.12] Make the iter_except() recipe more compact. (gh-116132) (gh011… · python/cpython@010aac7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 010aac7

Browse files
[3.12] Make the iter_except() recipe more compact. (gh-116132) (gh0116133)
1 parent 845123d commit 010aac7

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

Doc/library/itertools.rst

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -975,36 +975,17 @@ which incur interpreter overhead.
975975
""" Call a function repeatedly until an exception is raised.
976976

977977
Converts a call-until-exception interface to an iterator interface.
978-
Like builtins.iter(func, sentinel) but uses an exception instead
979-
of a sentinel to end the loop.
980-
981-
Priority queue iterator:
982-
iter_except(functools.partial(heappop, h), IndexError)
983-
984-
Non-blocking dictionary iterator:
985-
iter_except(d.popitem, KeyError)
986-
987-
Non-blocking deque iterator:
988-
iter_except(d.popleft, IndexError)
989-
990-
Non-blocking iterator over a producer Queue:
991-
iter_except(q.get_nowait, Queue.Empty)
992-
993-
Non-blocking set iterator:
994-
iter_except(s.pop, KeyError)
995-
996978
"""
979+
# iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
997980
try:
998981
if first is not None:
999-
# For database APIs needing an initial call to db.first()
1000982
yield first()
1001983
while True:
1002984
yield func()
1003985
except exception:
1004986
pass
1005987

1006988

1007-
1008989
The following recipes have a more mathematical flavor:
1009990

1010991
.. testcode::

0 commit comments

Comments
 (0)
0