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@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())
        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: https://www.python.org/psf/codeofconduct/
Andrew Svetlov