From 529b01d4b3123e882a5a956fa3f98e60d60d4d87 Mon Sep 17 00:00:00 2001 From: James Ward Date: Fri, 10 Nov 2023 19:36:14 -0500 Subject: [PATCH] chore: move CancelledError and InvalidStateError to tasks --- asyncio/core.py | 12 ++++++------ asyncio/task.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/asyncio/core.py b/asyncio/core.py index e31c1ce..3e08464 100644 --- a/asyncio/core.py +++ b/asyncio/core.py @@ -24,17 +24,17 @@ except: from .task import TaskQueue, Task +# Depending on the version of CircuitPython, these errors may exist in the build-in C code +# even if _asyncio exists +try: + from _asyncio import CancelledError, InvalidStateError +except: + from .task import CancelledError, InvalidStateError ################################################################################ # Exceptions -class CancelledError(BaseException): - """Injected into a task when calling `Task.cancel()`""" - - pass - - class TimeoutError(Exception): """Raised when waiting for a task longer than the specified timeout.""" diff --git a/asyncio/task.py b/asyncio/task.py index 2e3a6db..d9d6743 100644 --- a/asyncio/task.py +++ b/asyncio/task.py @@ -21,6 +21,18 @@ from . import core +class CancelledError(BaseException): + """Injected into a task when calling `Task.cancel()`""" + + pass + + +class InvalidStateError(Exception): + """Can be raised in situations like setting a result value for a task object that already has a result value set.""" + + pass + + # pairing-heap meld of 2 heaps; O(1) def ph_meld(h1, h2): if h1 is None: