Skip to content

Commit 45f7149

Browse files
authored
Merge pull request #55 from imnotjames/feat/53/cancelled-and-invalid-state
chore: move CancelledError and InvalidStateError to tasks
2 parents da943a7 + 3921b20 commit 45f7149

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Diff for: asyncio/core.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,27 @@
2121
# Import TaskQueue and Task, preferring built-in C code over Python code
2222
try:
2323
from _asyncio import TaskQueue, Task
24-
except:
24+
except ImportError:
2525
from .task import TaskQueue, Task
2626

27-
2827
################################################################################
2928
# Exceptions
3029

3130

32-
class CancelledError(BaseException):
33-
"""Injected into a task when calling `Task.cancel()`"""
31+
# Depending on the release of CircuitPython these errors may or may not
32+
# exist in the C implementation of `_asyncio`. However, when they
33+
# do exist, they must be preferred over the Python code.
34+
try:
35+
from _asyncio import CancelledError, InvalidStateError
36+
except (ImportError, AttributeError):
37+
class CancelledError(BaseException):
38+
"""Injected into a task when calling `Task.cancel()`"""
39+
pass
40+
3441

35-
pass
42+
class InvalidStateError(Exception):
43+
"""Can be raised in situations like setting a result value for a task object that already has a result value set."""
44+
pass
3645

3746

3847
class TimeoutError(Exception):

0 commit comments

Comments
 (0)