Fix pyright cr_code access on Coroutine in BaseObject.create_task
`collections.abc.Coroutine` doesn't expose `cr_code`/`co_name`; only native coroutine objects do. Use `getattr` chains so pyright is happy and any non-native awaitable falls back to a generic task name instead of crashing.
This commit is contained in:
@@ -133,11 +133,12 @@ class BaseObject(ABC):
|
||||
Returns:
|
||||
The created asyncio task.
|
||||
"""
|
||||
if name:
|
||||
name = f"{self}::{name}"
|
||||
else:
|
||||
name = f"{self}::{coroutine.cr_code.co_name}"
|
||||
return self.task_manager.create_task(coroutine, name)
|
||||
if not name:
|
||||
# Native coroutines expose ``cr_code``; fall back to a generic
|
||||
# name for any other awaitable subtype.
|
||||
cr_code = getattr(coroutine, "cr_code", None)
|
||||
name = getattr(cr_code, "co_name", "task")
|
||||
return self.task_manager.create_task(coroutine, f"{self}::{name}")
|
||||
|
||||
async def cancel_task(self, task: asyncio.Task, timeout: float | None = 1.0):
|
||||
"""Cancel a task managed by this object's task manager.
|
||||
|
||||
Reference in New Issue
Block a user