Skip to content

Commit

Permalink
Move .to_asyncio to modern optional value type annots
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Jul 21, 2023
1 parent bee2c36 commit e03bec5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tractor/to_asyncio.py
Expand Up @@ -28,7 +28,6 @@
Callable,
AsyncIterator,
Awaitable,
Optional,
)

import trio
Expand Down Expand Up @@ -65,9 +64,9 @@ class LinkedTaskChannel(trio.abc.Channel):
_trio_exited: bool = False

# set after ``asyncio.create_task()``
_aio_task: Optional[asyncio.Task] = None
_aio_err: Optional[BaseException] = None
_broadcaster: Optional[BroadcastReceiver] = None
_aio_task: asyncio.Task | None = None
_aio_err: BaseException | None = None
_broadcaster: BroadcastReceiver | None = None

async def aclose(self) -> None:
await self._from_aio.aclose()
Expand Down Expand Up @@ -188,7 +187,7 @@ def _run_asyncio_task(

cancel_scope = trio.CancelScope()
aio_task_complete = trio.Event()
aio_err: Optional[BaseException] = None
aio_err: BaseException | None = None

chan = LinkedTaskChannel(
aio_q, # asyncio.Queue
Expand Down Expand Up @@ -263,7 +262,7 @@ def cancel_trio(task: asyncio.Task) -> None:
'''
nonlocal chan
aio_err = chan._aio_err
task_err: Optional[BaseException] = None
task_err: BaseException | None = None

# only to avoid ``asyncio`` complaining about uncaptured
# task exceptions
Expand Down Expand Up @@ -329,11 +328,11 @@ async def translate_aio_errors(
'''
trio_task = trio.lowlevel.current_task()

aio_err: Optional[BaseException] = None
aio_err: BaseException | None = None

# TODO: make thisi a channel method?
def maybe_raise_aio_err(
err: Optional[Exception] = None
err: Exception | None = None
) -> None:
aio_err = chan._aio_err
if (
Expand Down

0 comments on commit e03bec5

Please sign in to comment.