Skip to content

Commit a81d950

Browse files
authored
Make the iter_except() recipe more compact. (gh-116132)
Only one example is needed
1 parent f0df35e commit a81d950

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
@@ -983,36 +983,17 @@ which incur interpreter overhead.
983983
""" Call a function repeatedly until an exception is raised.
984984

985985
Converts a call-until-exception interface to an iterator interface.
986-
Like builtins.iter(func, sentinel) but uses an exception instead
987-
of a sentinel to end the loop.
988-
989-
Priority queue iterator:
990-
iter_except(functools.partial(heappop, h), IndexError)
991-
992-
Non-blocking dictionary iterator:
993-
iter_except(d.popitem, KeyError)
994-
995-
Non-blocking deque iterator:
996-
iter_except(d.popleft, IndexError)
997-
998-
Non-blocking iterator over a producer Queue:
999-
iter_except(q.get_nowait, Queue.Empty)
1000-
1001-
Non-blocking set iterator:
1002-
iter_except(s.pop, KeyError)
1003-
1004986
"""
987+
# iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
1005988
try:
1006989
if first is not None:
1007-
# For database APIs needing an initial call to db.first()
1008990
yield first()
1009991
while True:
1010992
yield func()
1011993
except exception:
1012994
pass
1013995

1014996

1015-
1016997
The following recipes have a more mathematical flavor:
1017998

1018999
.. testcode::

0 commit comments

Comments
 (0)