Drop now-deprecated deps on modern `trio`/Python

- `trio_typing` is nearly obsolete since `trio >= 0.23`
- `exceptiongroup` is built-in to python 3.11
- `async_generator` primitives have lived in `contextlib` for quite
  a while!
mv_to_new_trio_py3.11
Tyler Goodlet 2024-03-13 18:41:24 -04:00
parent e5cb39804c
commit 71de56b09a
19 changed files with 47 additions and 48 deletions

View File

@ -0,0 +1,9 @@
'''
Reproduce a bug where enabling debug mode for a sub-actor actually causes
a hang on teardown...
'''
import asyncio
import trio
import tractor

View File

@ -8,7 +8,10 @@ This uses no extra threads, fancy semaphores or futures; all we need
is ``tractor``'s channels. is ``tractor``'s channels.
""" """
from contextlib import asynccontextmanager from contextlib import (
asynccontextmanager as acm,
aclosing,
)
from typing import Callable from typing import Callable
import itertools import itertools
import math import math
@ -16,7 +19,6 @@ import time
import tractor import tractor
import trio import trio
from async_generator import aclosing
PRIMES = [ PRIMES = [
@ -44,7 +46,7 @@ async def is_prime(n):
return True return True
@asynccontextmanager @acm
async def worker_pool(workers=4): async def worker_pool(workers=4):
"""Though it's a trivial special case for ``tractor``, the well """Though it's a trivial special case for ``tractor``, the well
known "worker pool" seems to be the defacto "but, I want this known "worker pool" seems to be the defacto "but, I want this

View File

@ -13,7 +13,7 @@ async def simple_rpc(
''' '''
# signal to parent that we're up much like # signal to parent that we're up much like
# ``trio_typing.TaskStatus.started()`` # ``trio.TaskStatus.started()``
await ctx.started(data + 1) await ctx.started(data + 1)
async with ctx.open_stream() as stream: async with ctx.open_stream() as stream:

View File

@ -47,9 +47,10 @@ setup(
# proper range spec: # proper range spec:
# https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#id5 # https://packaging.python.org/en/latest/discussions/install-requires-vs-requirements/#id5
'trio >= 0.24', 'trio >= 0.24',
'async_generator',
'trio_typing', # 'async_generator', # in stdlib mostly!
'exceptiongroup', # 'trio_typing', # trio==0.23.0 has type hints!
# 'exceptiongroup', # in stdlib as of 3.11!
# tooling # tooling
'stackscope', 'stackscope',

View File

@ -8,10 +8,6 @@ import platform
import time import time
from itertools import repeat from itertools import repeat
from exceptiongroup import (
BaseExceptionGroup,
ExceptionGroup,
)
import pytest import pytest
import trio import trio
import tractor import tractor

View File

@ -6,13 +6,15 @@ sub-sub-actor daemons.
''' '''
from typing import Optional from typing import Optional
import asyncio import asyncio
from contextlib import asynccontextmanager as acm from contextlib import (
asynccontextmanager as acm,
aclosing,
)
import pytest import pytest
import trio import trio
import tractor import tractor
from tractor import RemoteActorError from tractor import RemoteActorError
from async_generator import aclosing
async def aio_streamer( async def aio_streamer(

View File

@ -8,7 +8,6 @@ import builtins
import itertools import itertools
import importlib import importlib
from exceptiongroup import BaseExceptionGroup
import pytest import pytest
import trio import trio
import tractor import tractor

View File

@ -64,7 +64,8 @@ async def test_lifetime_stack_wipes_tmpfile(
except ( except (
tractor.RemoteActorError, tractor.RemoteActorError,
tractor.BaseExceptionGroup, # tractor.BaseExceptionGroup,
BaseExceptionGroup,
): ):
pass pass

View File

@ -5,7 +5,7 @@ want to see changed.
''' '''
import pytest import pytest
import trio import trio
from trio_typing import TaskStatus from trio import TaskStatus
@pytest.mark.parametrize( @pytest.mark.parametrize(

View File

@ -18,8 +18,6 @@
tractor: structured concurrent ``trio``-"actors". tractor: structured concurrent ``trio``-"actors".
""" """
from exceptiongroup import BaseExceptionGroup as BaseExceptionGroup
from ._clustering import ( from ._clustering import (
open_actor_cluster as open_actor_cluster, open_actor_cluster as open_actor_cluster,
) )

View File

@ -30,11 +30,10 @@ from typing import (
import textwrap import textwrap
import traceback import traceback
import exceptiongroup as eg
import trio import trio
from ._state import current_actor from tractor._state import current_actor
from .log import get_logger from tractor.log import get_logger
if TYPE_CHECKING: if TYPE_CHECKING:
from ._context import Context from ._context import Context
@ -373,7 +372,6 @@ def unpack_error(
for ns in [ for ns in [
builtins, builtins,
_this_mod, _this_mod,
eg,
trio, trio,
]: ]:
if suberror_type := getattr( if suberror_type := getattr(
@ -396,12 +394,13 @@ def unpack_error(
def is_multi_cancelled(exc: BaseException) -> bool: def is_multi_cancelled(exc: BaseException) -> bool:
''' '''
Predicate to determine if a possible ``eg.BaseExceptionGroup`` contains Predicate to determine if a possible ``BaseExceptionGroup`` contains
only ``trio.Cancelled`` sub-exceptions (and is likely the result of only ``trio.Cancelled`` sub-exceptions (and is likely the result of
cancelling a collection of subtasks. cancelling a collection of subtasks.
''' '''
if isinstance(exc, eg.BaseExceptionGroup): # if isinstance(exc, eg.BaseExceptionGroup):
if isinstance(exc, BaseExceptionGroup):
return exc.subgroup( return exc.subgroup(
lambda exc: isinstance(exc, trio.Cancelled) lambda exc: isinstance(exc, trio.Cancelled)
) is not None ) is not None

View File

@ -28,12 +28,13 @@ import os
import warnings import warnings
from exceptiongroup import BaseExceptionGroup
import trio import trio
from ._runtime import ( from ._runtime import (
Actor, Actor,
Arbiter, Arbiter,
# TODO: rename and make a non-actor subtype?
# Arbiter as Registry,
async_main, async_main,
) )
from .devx import _debug from .devx import _debug

View File

@ -21,6 +21,7 @@ Remote (task) Procedure Call (scheduling) with SC transitive semantics.
from __future__ import annotations from __future__ import annotations
from contextlib import ( from contextlib import (
asynccontextmanager as acm, asynccontextmanager as acm,
aclosing,
) )
from functools import partial from functools import partial
import inspect import inspect
@ -34,17 +35,12 @@ from typing import (
) )
import warnings import warnings
from async_generator import aclosing
from exceptiongroup import BaseExceptionGroup
import trio import trio
from trio import ( from trio import (
CancelScope, CancelScope,
Nursery, Nursery,
TaskStatus, TaskStatus,
) )
# from trio_typing import (
# TaskStatus,
# )
from .msg import NamespacePath from .msg import NamespacePath
from ._ipc import Channel from ._ipc import Channel

View File

@ -61,8 +61,6 @@ import warnings
import trio import trio
from trio import ( from trio import (
CancelScope, CancelScope,
)
from trio_typing import (
Nursery, Nursery,
TaskStatus, TaskStatus,
) )

View File

@ -46,7 +46,7 @@ if _USE_POSIX:
try: try:
import numpy as np import numpy as np
from numpy.lib import recfunctions as rfn from numpy.lib import recfunctions as rfn
import nptyping # import nptyping
except ImportError: except ImportError:
pass pass

View File

@ -31,25 +31,24 @@ from typing import (
TYPE_CHECKING, TYPE_CHECKING,
) )
from exceptiongroup import BaseExceptionGroup
import trio import trio
from trio_typing import TaskStatus from trio import TaskStatus
from .devx import ( from tractor.devx import (
maybe_wait_for_debugger, maybe_wait_for_debugger,
acquire_debug_lock, acquire_debug_lock,
) )
from ._state import ( from tractor._state import (
current_actor, current_actor,
is_main_process, is_main_process,
is_root_process, is_root_process,
debug_mode, debug_mode,
) )
from .log import get_logger from tractor.log import get_logger
from ._portal import Portal from tractor._portal import Portal
from ._runtime import Actor from tractor._runtime import Actor
from ._entry import _mp_main from tractor._entry import _mp_main
from ._exceptions import ActorFailure from tractor._exceptions import ActorFailure
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -26,7 +26,6 @@ from typing import TYPE_CHECKING
import typing import typing
import warnings import warnings
from exceptiongroup import BaseExceptionGroup
import trio import trio
from .devx._debug import maybe_wait_for_debugger from .devx._debug import maybe_wait_for_debugger

View File

@ -31,7 +31,7 @@ from typing import (
Callable, Callable,
) )
from functools import partial from functools import partial
from async_generator import aclosing from contextlib import aclosing
import trio import trio
import wrapt import wrapt

View File

@ -33,10 +33,9 @@ from typing import (
) )
import trio import trio
from trio_typing import TaskStatus
from .._state import current_actor from tractor._state import current_actor
from ..log import get_logger from tractor.log import get_logger
log = get_logger(__name__) log = get_logger(__name__)
@ -184,7 +183,7 @@ class _Cache:
cls, cls,
mng, mng,
ctx_key: tuple, ctx_key: tuple,
task_status: TaskStatus[T] = trio.TASK_STATUS_IGNORED, task_status: trio.TaskStatus[T] = trio.TASK_STATUS_IGNORED,
) -> None: ) -> None:
async with mng as value: async with mng as value: