From c5ae476668d3f4d74db74e56c8db8e3aadb8dcbd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Apr 2024 01:01:36 -0700 Subject: [PATCH] Bump mypy from 0.931 to 1.9.0 (#197) * Bump mypy from 0.931 to 1.9.0 Bumps [mypy](https://github.com/python/mypy) from 0.931 to 1.9.0. - [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md) - [Commits](https://github.com/python/mypy/compare/v0.931...1.9.0) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * type fixes --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Amethyst Reese --- aiomultiprocess/core.py | 27 +++++++++++++++------------ aiomultiprocess/pool.py | 10 +++++----- pyproject.toml | 2 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/aiomultiprocess/core.py b/aiomultiprocess/core.py index 75587a6..5bd13b0 100644 --- a/aiomultiprocess/core.py +++ b/aiomultiprocess/core.py @@ -4,6 +4,7 @@ import asyncio import logging import multiprocessing +import multiprocessing.context import multiprocessing.managers import os import sys @@ -16,7 +17,9 @@ # shared context for all multiprocessing primitives, for platform compatibility # "spawn" is default/required on windows and mac, but can't execute non-global functions # see https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods -context = multiprocessing.get_context(DEFAULT_START_METHOD) +context: multiprocessing.context.BaseContext = multiprocessing.get_context( + DEFAULT_START_METHOD +) _manager = None log = logging.getLogger(__name__) @@ -80,12 +83,12 @@ class Process: def __init__( self, group: None = None, - target: Callable = None, - name: str = None, - args: Sequence[Any] = None, - kwargs: Dict[str, Any] = None, + target: Optional[Callable] = None, + name: Optional[str] = None, + args: Optional[Sequence[Any]] = None, + kwargs: Optional[Dict[str, Any]] = None, *, - daemon: bool = None, + daemon: Optional[bool] = None, initializer: Optional[Callable] = None, initargs: Sequence[Any] = (), loop_initializer: Optional[Callable] = None, @@ -111,7 +114,7 @@ def __init__( initargs=initargs, loop_initializer=loop_initializer, ) - self.aio_process = context.Process( + self.aio_process = context.Process( # type: ignore[attr-defined] group=group, target=process_target or Process.run_async, args=(self.unit,), @@ -127,7 +130,7 @@ def __await__(self) -> Any: return self.join().__await__() @staticmethod - def run_async(unit: Unit) -> R: + def run_async(unit: Unit) -> R: # type: ignore[type-var] """Initialize the child process and event loop, then execute the coroutine.""" try: if unit.loop_initializer is None: @@ -152,7 +155,7 @@ def start(self) -> None: """Start the child process.""" return self.aio_process.start() - async def join(self, timeout: int = None) -> None: + async def join(self, timeout: Optional[int] = None) -> None: """Wait for the process to finish execution without blocking the main thread.""" if not self.is_alive() and self.exitcode is None: raise ValueError("must start process before joining it") @@ -216,7 +219,7 @@ def __init__(self, *args, **kwargs) -> None: self.unit.namespace.result = None @staticmethod - def run_async(unit: Unit) -> R: + def run_async(unit: Unit) -> R: # type: ignore[type-var] """Initialize the child process and event loop, then execute the coroutine.""" try: result: R = Process.run_async(unit) @@ -227,13 +230,13 @@ def run_async(unit: Unit) -> R: unit.namespace.result = e raise - async def join(self, timeout: int = None) -> Any: + async def join(self, timeout: Optional[int] = None) -> Any: """Wait for the worker to finish, and return the final result.""" await super().join(timeout) return self.result @property - def result(self) -> R: + def result(self) -> R: # type: ignore[type-var] """Easy access to the resulting value from the coroutine.""" if self.exitcode is None: raise ValueError("coroutine not completed") diff --git a/aiomultiprocess/pool.py b/aiomultiprocess/pool.py index a3e0821..93e7603 100644 --- a/aiomultiprocess/pool.py +++ b/aiomultiprocess/pool.py @@ -150,13 +150,13 @@ class Pool: def __init__( self, - processes: int = None, - initializer: Callable[..., None] = None, + processes: Optional[int] = None, + initializer: Optional[Callable[..., None]] = None, initargs: Sequence[Any] = (), maxtasksperchild: int = MAX_TASKS_PER_CHILD, childconcurrency: int = CHILD_CONCURRENCY, queuecount: Optional[int] = None, - scheduler: Scheduler = None, + scheduler: Optional[Scheduler] = None, loop_initializer: Optional[LoopInitializer] = None, exception_handler: Optional[Callable[[BaseException], None]] = None, ) -> None: @@ -316,8 +316,8 @@ async def results(self, tids: Sequence[TaskID]) -> Sequence[R]: async def apply( self, func: Callable[..., Awaitable[R]], - args: Sequence[Any] = None, - kwds: Dict[str, Any] = None, + args: Optional[Sequence[Any]] = None, + kwds: Optional[Dict[str, Any]] = None, ) -> R: """Run a single coroutine on the pool.""" if not self.running: diff --git a/pyproject.toml b/pyproject.toml index 1d40360..e3f1539 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dev = [ "flake8==7.0.0", "flake8-bugbear==24.4.21", "flit==3.9.0", - "mypy==0.931", + "mypy==1.9.0", "usort==1.0.8.post1", "uvloop==0.19.0; sys_platform != 'win32'", ]