Sounds like an implementation issue. The Future class has a boolean flag indicating whether it's been cancelled, and everything then raises CancelledError when that flag is set. I suppose we could replace that flag with an instance of CancelledError, and when we *catch* CancelledError we set it to that. But it seems messy and I'm not sure that you should attempt this. IMO you should define an exception that does *not* derive from CancelledError and raise that -- it will properly be transmitted. What's your reason for not doing that? IOW why are you trying to pump more than a bit through the narrow "cancelled" channel?

On Sun, Dec 3, 2017 at 2:11 AM, Andrew Svetlov <> wrote:
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 <> 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())
        await task
    except Exception:
    assert task.cancelled()
    # Raises CancelledError and not MyCancelledError.

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,
Async-sig mailing list
Code of Conduct:
Andrew Svetlov

Async-sig mailing list
Code of Conduct:

--Guido van Rossum (