Consider the following code, which creates a generator that
immediately returns 1, and then catches the StopIteration twice.
def generatorfunction():
if False: yield
return 1
def get_return(gen):
try:
next(gen)
except StopIteration as e:
IIRC we considered this when we designed this (PEP 380) and decided that
hanging on to the exception object longer than necessary was not in our
best interest.
On Mon, Dec 11, 2017 at 1:10 AM, Franklin? Lee <
[email protected]> wrote:
> Consider the following code, which creates a gen
What about hanging onto just the value, and creating new StopIteration
instances instead of raising the same one again?
On Mon, Dec 11, 2017 at 3:06 PM, Guido van Rossum wrote:
> IIRC we considered this when we designed this (PEP 380) and decided that
> hanging on to the exception object longer t
On Mon, Dec 11, 2017 at 6:21 PM, Franklin? Lee
wrote:
> What about hanging onto just the value, and creating new StopIteration
> instances instead of raising the same one again?
Doesn't really matter, as we're still prolonging the lifespan of the
returned object.
To me the current behaviour of g
On Mon, Dec 11, 2017 at 6:44 PM, Yury Selivanov wrote:
> On Mon, Dec 11, 2017 at 6:21 PM, Franklin? Lee
> wrote:
>> What about hanging onto just the value, and creating new StopIteration
>> instances instead of raising the same one again?
>
> Doesn't really matter, as we're still prolonging the l