Opened 3 years ago

Last modified 20 months ago

#9560 defect new doesn't set Failure when StopIteration is raised

Reported by: Allison Kaptur Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Glyph Branch:


I have a coroutine that incorrectly raised a StopIteration. fail consumed the StopIteration and returned a Deferred in the success state, instead of one with Failure set.

Repro steps:

>>> from twisted.internet.defer import fail, ensureDeferred
>>> async def g(x):
...     return await x

>>> ensureDeferred(g(fail(Exception())))   # expected
<Deferred at 0x107d35400 current result: <twisted.python.failure.Failure builtins.Exception: >>

>>> ensureDeferred(g(fail(StopIteration())))  # surprising
<Deferred at 0x107d205f8 current result: None>

This is Twisted 18.9.0 and Python 3.6.5.

Change History (2)

comment:1 Changed 3 years ago by Glyph

Cc: Glyph added

comment:2 Changed 20 months ago by Glyph

I think this is pretty closely related to #7767 given some of the shared machinery here?

Note: See TracTickets for help on using tickets.