Skip to content

Commit

Permalink
Use built-ins for all data-structure-type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Sep 15, 2022
1 parent 3f6ac83 commit f07ddf1
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 62 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ tasks spawned via multiple RPC calls to an actor can modify
# a per process cache
_actor_cache: Dict[str, bool] = {}
_actor_cache: dict[str, bool] = {}
def ping_endpoints(endpoints: List[str]):
Expand Down
6 changes: 3 additions & 3 deletions examples/parallelism/concurrent_actors_primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""
from contextlib import asynccontextmanager
from typing import List, Callable
from typing import Callable
import itertools
import math
import time
Expand Down Expand Up @@ -71,8 +71,8 @@ async def worker_pool(workers=4):

async def _map(
worker_func: Callable[[int], bool],
sequence: List[int]
) -> List[bool]:
sequence: list[int]
) -> list[bool]:

# define an async (local) task to collect results from workers
async def send_result(func, value, portal):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_advanced_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections import Counter
import itertools
import platform
from typing import Set, Dict, List

import trio
import tractor
Expand All @@ -15,7 +14,7 @@ def is_win():
return platform.system() == 'Windows'


_registry: Dict[str, Set[tractor.ReceiveMsgStream]] = {
_registry: dict[str, set[tractor.ReceiveMsgStream]] = {
'even': set(),
'odd': set(),
}
Expand Down Expand Up @@ -77,7 +76,7 @@ async def subscribe(

async def consumer(

subs: List[str],
subs: list[str],

) -> None:

Expand Down
6 changes: 3 additions & 3 deletions tests/test_spawning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Spawning basics
"""
from typing import Dict, Tuple, Optional
from typing import Optional

import pytest
import trio
Expand All @@ -14,8 +14,8 @@

async def spawn(
is_arbiter: bool,
data: Dict,
arb_addr: Tuple[str, int],
data: dict,
arb_addr: tuple[str, int],
):
namespaces = [__name__]

Expand Down
6 changes: 3 additions & 3 deletions tests/test_task_broadcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import partial
from itertools import cycle
import time
from typing import Optional, List, Tuple
from typing import Optional

import pytest
import trio
Expand Down Expand Up @@ -62,8 +62,8 @@ async def ensure_sequence(
@asynccontextmanager
async def open_sequence_streamer(

sequence: List[int],
arb_addr: Tuple[str, int],
sequence: list[int],
arb_addr: tuple[str, int],
start_method: str,

) -> tractor.MsgStream:
Expand Down
11 changes: 5 additions & 6 deletions tractor/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from functools import partial
from contextlib import asynccontextmanager as acm
from typing import (
Tuple,
Optional,
Callable,
AsyncIterator,
Expand Down Expand Up @@ -74,7 +73,7 @@ class Lock:
local_task_in_debug: Optional[str] = None

# actor tree-wide actor uid that supposedly has the tty lock
global_actor_in_debug: Optional[Tuple[str, str]] = None
global_actor_in_debug: Optional[tuple[str, str]] = None

local_pdb_complete: Optional[trio.Event] = None
no_remote_has_tty: Optional[trio.Event] = None
Expand Down Expand Up @@ -172,7 +171,7 @@ def set_quit(self):

@acm
async def _acquire_debug_lock_from_root_task(
uid: Tuple[str, str]
uid: tuple[str, str]

) -> AsyncIterator[trio.StrictFIFOLock]:
'''
Expand Down Expand Up @@ -252,7 +251,7 @@ async def _acquire_debug_lock_from_root_task(
async def lock_tty_for_child(

ctx: tractor.Context,
subactor_uid: Tuple[str, str]
subactor_uid: tuple[str, str]

) -> str:
'''
Expand Down Expand Up @@ -302,7 +301,7 @@ async def lock_tty_for_child(


async def wait_for_parent_stdin_hijack(
actor_uid: Tuple[str, str],
actor_uid: tuple[str, str],
task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED
):
'''
Expand Down Expand Up @@ -732,7 +731,7 @@ async def _maybe_enter_pm(err):

@acm
async def acquire_debug_lock(
subactor_uid: Tuple[str, str],
subactor_uid: tuple[str, str],
) -> AsyncGenerator[None, tuple]:
'''
Grab root's debug lock on entry, release on exit.
Expand Down
10 changes: 7 additions & 3 deletions tractor/_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
Actor discovery API.
"""
from typing import Tuple, Optional, Union, AsyncGenerator
from typing import (
Optional,
Union,
AsyncGenerator,
)
from contextlib import asynccontextmanager as acm

from ._ipc import _connect_chan, Channel
Expand Down Expand Up @@ -104,7 +108,7 @@ async def query_actor(
@acm
async def find_actor(
name: str,
arbiter_sockaddr: Tuple[str, int] = None
arbiter_sockaddr: tuple[str, int] = None

) -> AsyncGenerator[Optional[Portal], None]:
'''
Expand All @@ -130,7 +134,7 @@ async def find_actor(
@acm
async def wait_for_actor(
name: str,
arbiter_sockaddr: Tuple[str, int] = None
arbiter_sockaddr: tuple[str, int] = None
) -> AsyncGenerator[Portal, None]:
"""Wait on an actor to register with the arbiter.
Expand Down
10 changes: 5 additions & 5 deletions tractor/_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
from functools import partial
from typing import Tuple, Any
from typing import Any

import trio # type: ignore

Expand All @@ -35,10 +35,10 @@
def _mp_main(

actor: 'Actor', # type: ignore
accept_addr: Tuple[str, int],
forkserver_info: Tuple[Any, Any, Any, Any, Any],
accept_addr: tuple[str, int],
forkserver_info: tuple[Any, Any, Any, Any, Any],
start_method: str,
parent_addr: Tuple[str, int] = None,
parent_addr: tuple[str, int] = None,
infect_asyncio: bool = False,

) -> None:
Expand Down Expand Up @@ -85,7 +85,7 @@ def _trio_main(

actor: Actor, # type: ignore
*,
parent_addr: Tuple[str, int] = None,
parent_addr: tuple[str, int] = None,
infect_asyncio: bool = False,

) -> None:
Expand Down
10 changes: 7 additions & 3 deletions tractor/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
Our classy exception set.
"""
from typing import Dict, Any, Optional, Type
from typing import (
Any,
Optional,
Type,
)
import importlib
import builtins
import traceback
Expand Down Expand Up @@ -95,7 +99,7 @@ def pack_error(
exc: BaseException,
tb=None,

) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Create an "error message" for tranmission over
a channel (aka the wire).
"""
Expand All @@ -114,7 +118,7 @@ def pack_error(

def unpack_error(

msg: Dict[str, Any],
msg: dict[str, Any],
chan=None,
err_type=RemoteActorError

Expand Down
7 changes: 5 additions & 2 deletions tractor/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
Per process state
"""
from typing import Optional, Dict, Any
from typing import (
Optional,
Any,
)
from collections.abc import Mapping

import trio
Expand All @@ -27,7 +30,7 @@


_current_actor: Optional['Actor'] = None # type: ignore # noqa
_runtime_vars: Dict[str, Any] = {
_runtime_vars: dict[str, Any] = {
'_debug_mode': False,
'_is_root': False,
'_root_mailbox': (None, None)
Expand Down
8 changes: 5 additions & 3 deletions tractor/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import (
Any, Optional, Callable,
AsyncGenerator, Dict,
Any,
Optional,
Callable,
AsyncGenerator,
AsyncIterator
)

Expand Down Expand Up @@ -393,7 +395,7 @@ async def send_stop(self) -> None:

async def _maybe_raise_from_remote_msg(
self,
msg: Dict[str, Any],
msg: dict[str, Any],

) -> None:
'''
Expand Down
29 changes: 16 additions & 13 deletions tractor/_supervise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"""
from functools import partial
import inspect
from typing import Tuple, List, Dict, Optional, TYPE_CHECKING
from typing import (
Optional,
TYPE_CHECKING,
)
import typing
import warnings

Expand All @@ -43,7 +46,7 @@

log = get_logger(__name__)

_default_bind_addr: Tuple[str, int] = ('127.0.0.1', 0)
_default_bind_addr: tuple[str, int] = ('127.0.0.1', 0)


class ActorNursery:
Expand Down Expand Up @@ -79,15 +82,15 @@ def __init__(
actor: Actor,
ria_nursery: trio.Nursery,
da_nursery: trio.Nursery,
errors: Dict[Tuple[str, str], Exception],
errors: dict[tuple[str, str], Exception],
) -> None:
# self.supervisor = supervisor # TODO
self._actor: Actor = actor
self._ria_nursery = ria_nursery
self._da_nursery = da_nursery
self._children: Dict[
Tuple[str, str],
Tuple[Actor, mp.Process, Optional[Portal]]
self._children: dict[
tuple[str, str],
tuple[Actor, mp.Process, Optional[Portal]]
] = {}
# portals spawned with ``run_in_actor()`` are
# cancelled when their "main" result arrives
Expand All @@ -102,9 +105,9 @@ async def start_actor(
self,
name: str,
*,
bind_addr: Tuple[str, int] = _default_bind_addr,
rpc_module_paths: List[str] = None,
enable_modules: List[str] = None,
bind_addr: tuple[str, int] = _default_bind_addr,
rpc_module_paths: list[str] = None,
enable_modules: list[str] = None,
loglevel: str = None, # set log level per subactor
nursery: trio.Nursery = None,
debug_mode: Optional[bool] = None,
Expand Down Expand Up @@ -173,9 +176,9 @@ async def run_in_actor(
*,

name: Optional[str] = None,
bind_addr: Tuple[str, int] = _default_bind_addr,
rpc_module_paths: Optional[List[str]] = None,
enable_modules: List[str] = None,
bind_addr: tuple[str, int] = _default_bind_addr,
rpc_module_paths: Optional[list[str]] = None,
enable_modules: list[str] = None,
loglevel: str = None, # set log level per subactor
infect_asyncio: bool = False,

Expand Down Expand Up @@ -293,7 +296,7 @@ async def _open_and_supervise_one_cancels_all_nursery(
) -> typing.AsyncGenerator[ActorNursery, None]:

# the collection of errors retreived from spawned sub-actors
errors: Dict[Tuple[str, str], Exception] = {}
errors: dict[tuple[str, str], Exception] = {}

# This is the outermost level "deamon actor" nursery. It is awaited
# **after** the below inner "run in actor nursery". This allows for
Expand Down
Loading

0 comments on commit f07ddf1

Please sign in to comment.