Skip to content

Commit

Permalink
23.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemanspiff2007 committed Nov 23, 2023
1 parent 1c0a597 commit 9386ddd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/HABApp/core/asyncio.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from asyncio import Future as _Future
from asyncio import Task as _Task
from asyncio import run_coroutine_threadsafe as _run_coroutine_threadsafe
from contextvars import ContextVar as _ContextVar
from contextvars import Token
from typing import Any as _Any
from typing import Callable, Final, Optional
from typing import Callable, Final
from typing import Callable as _Callable
from typing import Coroutine as _Coroutine
from typing import Optional as _Optional
from typing import TypeVar as _TypeVar

from HABApp.core.const import loop
Expand All @@ -26,8 +27,8 @@
class AsyncContext:
def __init__(self, value: str):
self.value: Final = value
self.token: Optional[Token[str]] = None
self.parent: Optional[AsyncContext] = None
self.token: Token[str] | None = None
self.parent: AsyncContext | None = None

def __enter__(self):
assert self.token is None, self
Expand Down Expand Up @@ -59,7 +60,7 @@ def __str__(self):
_T = _TypeVar('_T')


def create_task(coro: _Coroutine[_Any, _Any, _T], name: _Optional[str] = None) -> _Future[_T]:
def create_task(coro: _Coroutine[_Any, _Any, _T], name: str | None = None) -> _Future[_T]:
# https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
if async_context.get(None) is None:
f = _run_coroutine_threadsafe(coro, loop)
Expand All @@ -73,7 +74,7 @@ def create_task(coro: _Coroutine[_Any, _Any, _T], name: _Optional[str] = None) -
return t


def create_task_from_async(coro: _Coroutine[_Any, _Any, _T], name: _Optional[str] = None) -> _Task[_T]:
def create_task_from_async(coro: _Coroutine[_Any, _Any, _T], name: str | None = None) -> _Task[_T]:
t = loop.create_task(coro, name=name)
_tasks.add(t)
t.add_done_callback(_tasks.discard)
Expand Down

0 comments on commit 9386ddd

Please sign in to comment.