[Async-sig] subclassing CancelledError
Andrew Svetlov
andrew.svetlov at gmail.com
Sun Dec 3 05:11:49 EST 2017
IIRC at very early stages Guido van Rossum decided to *freeze*
`CancelledError`: user code should not derive from the exception. Like you
never derive from StopIteration.
On Sun, Dec 3, 2017 at 8:00 AM Chris Jerdonek <chris.jerdonek at gmail.com>
wrote:
> Hi, I want to ask how people feel about the following.
>
> If you raise a subclass of CancelledError from within a task and then
> call task.result(), CancelledError is raised rather than the subclass.
>
> Here is some code to illustrate:
>
> class MyCancelledError(CancelledError): pass
>
> async def raise_my_cancel():
> raise MyCancelledError()
>
> task = asyncio.ensure_future(raise_my_cancel())
> try:
> await task
> except Exception:
> pass
> assert task.cancelled()
> # Raises CancelledError and not MyCancelledError.
> task.result()
>
> Does this seem right to people? Is there a justification for this?
>
> If it would help for the discussion, I could provide a use case.
>
> Thanks a lot,
> --Chris
> _______________________________________________
> Async-sig mailing list
> Async-sig at python.org
> https://mail.python.org/mailman/listinfo/async-sig
> Code of Conduct: https://www.python.org/psf/codeofconduct/
>
--
Thanks,
Andrew Svetlov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20171203/e9d345e3/attachment.html>
More information about the Async-sig
mailing list