File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,20 @@ at the time of writing only two responses have been received: one was
179
179
in favor of changing list comprehensions to match generator
180
180
expressions (!), the other was in favor of this PEP's main proposal.
181
181
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
+
182
196
183
197
References
184
198
==========
You can’t perform that action at this time.
0 commit comments