Skip to content

Commit 695961d

Browse files
committed
Add an answer to criticism based on Nick Coghlan's comments
1 parent 03bf43c commit 695961d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pep-0479.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ at the time of writing only two responses have been received: one was
179179
in favor of changing list comprehensions to match generator
180180
expressions (!), the other was in favor of this PEP's main proposal.
181181

182+
The existing model has been compared to the perfectly-acceptable
183+
issues inherent to every other case where an exception has special
184+
meaning. For instance, an unexpected ``KeyError`` inside a
185+
``__getitem__`` method will be interpreted as failure, rather than
186+
permitted to bubble up. However, there is a difference. Dunder
187+
methods use ``return`` to indicate normality, and ``raise`` to signal
188+
abnormality; generators ``yield`` to indicate data, and ``return`` to
189+
signal the abnormal state. This makes explicitly raising
190+
``StopIteration`` entirely redundant, and potentially surprising. If
191+
other dunder methods had dedicated keywords to distinguish between
192+
their return paths, they too could turn unexpected exceptions into
193+
``RuntimeError``; the fact that they cannot should not preclude
194+
generators from doing so.
195+
182196

183197
References
184198
==========

0 commit comments

Comments
 (0)