From c3e5b4e6792088c7a38337bd4af238bdc6896b48 Mon Sep 17 00:00:00 2001 From: phi Date: Tue, 30 Jul 2024 21:38:42 +0900 Subject: [PATCH] fix: ruff, pyright 38 -> 39 --- pyrightconfig.json | 2 +- ruff.toml | 2 +- src/async_wrapper/convert/_async.py | 5 +++- src/async_wrapper/convert/_sync/main.py | 5 +++- src/async_wrapper/convert/_sync/sqlalchemy.py | 4 ++- src/async_wrapper/convert/main.py | 5 +++- src/async_wrapper/pipe.py | 12 +++------ src/async_wrapper/queue.py | 26 ++++++++----------- src/async_wrapper/task_group/task_group.py | 3 ++- src/async_wrapper/wait.py | 3 ++- tests/convert/test_async.py | 3 ++- tests/convert/test_sync.py | 3 ++- tests/test_pipe.py | 3 ++- 13 files changed, 41 insertions(+), 35 deletions(-) diff --git a/pyrightconfig.json b/pyrightconfig.json index a4a9628..c96b65e 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -4,7 +4,7 @@ "tests" ], "typeCheckingMode": "strict", - "pythonVersion": "3.8", + "pythonVersion": "3.9", "pythonPlatform": "Linux", "reportMissingTypeStubs": false, "reportInconsistentConstructor": false, diff --git a/ruff.toml b/ruff.toml index fcd72ae..69458d5 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,6 +1,6 @@ line-length = 88 unsafe-fixes = true -target-version = "py38" +target-version = "py39" [lint] select = ["ALL"] diff --git a/src/async_wrapper/convert/_async.py b/src/async_wrapper/convert/_async.py index 3092c65..ea70f90 100644 --- a/src/async_wrapper/convert/_async.py +++ b/src/async_wrapper/convert/_async.py @@ -1,11 +1,14 @@ from __future__ import annotations from functools import partial, wraps -from typing import Any, Callable, Coroutine +from typing import TYPE_CHECKING, Any, Callable from anyio import to_thread from typing_extensions import ParamSpec, TypeVar +if TYPE_CHECKING: + from collections.abc import Coroutine + ValueT = TypeVar("ValueT", infer_variance=True) ParamT = ParamSpec("ParamT") diff --git a/src/async_wrapper/convert/_sync/main.py b/src/async_wrapper/convert/_sync/main.py index 7a2df8f..15d59a8 100644 --- a/src/async_wrapper/convert/_sync/main.py +++ b/src/async_wrapper/convert/_sync/main.py @@ -4,7 +4,7 @@ from contextvars import ContextVar from functools import partial, wraps from importlib.util import find_spec -from typing import Any, Awaitable, Callable, Coroutine, overload +from typing import TYPE_CHECKING, Any, Callable, overload import anyio from sniffio import AsyncLibraryNotFoundError, current_async_library @@ -12,6 +12,9 @@ from async_wrapper.convert._sync.sqlalchemy import check_is_unset, run_sa_greenlet +if TYPE_CHECKING: + from collections.abc import Awaitable, Coroutine + ValueT = TypeVar("ValueT", infer_variance=True) ParamT = ParamSpec("ParamT") AnyAwaitable: TypeAlias = "Awaitable[ValueT] | Coroutine[Any, Any, ValueT]" diff --git a/src/async_wrapper/convert/_sync/sqlalchemy.py b/src/async_wrapper/convert/_sync/sqlalchemy.py index 557d0e8..e59671b 100644 --- a/src/async_wrapper/convert/_sync/sqlalchemy.py +++ b/src/async_wrapper/convert/_sync/sqlalchemy.py @@ -1,11 +1,13 @@ from __future__ import annotations from contextlib import suppress -from typing import TYPE_CHECKING, Any, Awaitable, Coroutine +from typing import TYPE_CHECKING, Any from typing_extensions import TypeAlias, TypeGuard, TypeVar if TYPE_CHECKING: + from collections.abc import Awaitable, Coroutine + import greenlet diff --git a/src/async_wrapper/convert/main.py b/src/async_wrapper/convert/main.py index 3afb55a..64ef93a 100644 --- a/src/async_wrapper/convert/main.py +++ b/src/async_wrapper/convert/main.py @@ -1,13 +1,16 @@ from __future__ import annotations from inspect import iscoroutinefunction -from typing import Any, Callable, Coroutine, overload +from typing import TYPE_CHECKING, Any, Callable, overload from typing_extensions import ParamSpec, TypeVar from async_wrapper.convert._async import sync_to_async from async_wrapper.convert._sync import async_to_sync +if TYPE_CHECKING: + from collections.abc import Coroutine + ValueT = TypeVar("ValueT", infer_variance=True) ParamT = ParamSpec("ParamT") diff --git a/src/async_wrapper/pipe.py b/src/async_wrapper/pipe.py index 64b62ae..515af4e 100644 --- a/src/async_wrapper/pipe.py +++ b/src/async_wrapper/pipe.py @@ -3,15 +3,7 @@ import threading from collections import deque from contextlib import AsyncExitStack, suppress -from typing import ( - TYPE_CHECKING, - Any, - Awaitable, - Callable, - Generic, - Protocol, - runtime_checkable, -) +from typing import TYPE_CHECKING, Any, Callable, Generic, Protocol, runtime_checkable import anyio from typing_extensions import TypedDict, TypeVar, override @@ -19,6 +11,8 @@ from async_wrapper.exception import AlreadyDisposedError if TYPE_CHECKING: + from collections.abc import Awaitable + from anyio.abc import CapacityLimiter, Lock, Semaphore class Synchronization(TypedDict, total=False): diff --git a/src/async_wrapper/queue.py b/src/async_wrapper/queue.py index 857a69c..88e793d 100644 --- a/src/async_wrapper/queue.py +++ b/src/async_wrapper/queue.py @@ -2,18 +2,13 @@ import math import sys -from contextlib import asynccontextmanager, contextmanager -from typing import ( - TYPE_CHECKING, - Any, - AsyncContextManager, - AsyncGenerator, - ContextManager, - Generator, - Generic, - Literal, - NoReturn, +from contextlib import ( + AbstractAsyncContextManager, + AbstractContextManager, + asynccontextmanager, + contextmanager, ) +from typing import TYPE_CHECKING, Any, Generic, Literal, NoReturn from anyio import WouldBlock, create_memory_object_stream, create_task_group, fail_after from anyio.streams.memory import BrokenResourceError, ClosedResourceError, EndOfStream @@ -31,6 +26,7 @@ from exceptiongroup import ExceptionGroup if TYPE_CHECKING: + from collections.abc import AsyncGenerator, Generator from types import TracebackType from anyio.streams.memory import ( @@ -131,22 +127,22 @@ def _init( self._close_getter: bool = True @property - def aputter(self) -> AsyncContextManager[Self]: + def aputter(self) -> AbstractAsyncContextManager[Self]: """aclose putter only""" return self._as_aputter() @property - def agetter(self) -> AsyncContextManager[Self]: + def agetter(self) -> AbstractAsyncContextManager[Self]: """aclose getter only""" return self._as_agetter() @property - def putter(self) -> ContextManager[Self]: + def putter(self) -> AbstractContextManager[Self]: """close putter only""" return self._as_putter() @property - def getter(self) -> ContextManager[Self]: + def getter(self) -> AbstractContextManager[Self]: """close getter only""" return self._as_getter() diff --git a/src/async_wrapper/task_group/task_group.py b/src/async_wrapper/task_group/task_group.py index c61c47f..4c0d2fb 100644 --- a/src/async_wrapper/task_group/task_group.py +++ b/src/async_wrapper/task_group/task_group.py @@ -2,7 +2,7 @@ from contextlib import AsyncExitStack from functools import partial, wraps -from typing import TYPE_CHECKING, Any, Awaitable, Callable, Coroutine, Generic +from typing import TYPE_CHECKING, Any, Callable, Generic from anyio import create_task_group as _create_task_group from anyio.abc import TaskGroup as _TaskGroup @@ -11,6 +11,7 @@ from async_wrapper.task_group.value import SoonValue if TYPE_CHECKING: + from collections.abc import Awaitable, Coroutine from types import TracebackType from anyio.abc import CancelScope, CapacityLimiter, Lock, Semaphore diff --git a/src/async_wrapper/wait.py b/src/async_wrapper/wait.py index d68c739..0225e6c 100644 --- a/src/async_wrapper/wait.py +++ b/src/async_wrapper/wait.py @@ -1,7 +1,7 @@ from __future__ import annotations from functools import partial -from typing import TYPE_CHECKING, Any, Awaitable, Callable, Iterable +from typing import TYPE_CHECKING, Any, Callable from anyio import EndOfStream, Event, create_memory_object_stream, create_task_group from typing_extensions import ParamSpec, Self, TypeVar, override @@ -9,6 +9,7 @@ from async_wrapper.exception import PendingError if TYPE_CHECKING: + from collections.abc import Awaitable, Iterable from types import TracebackType from anyio import EventStatistics diff --git a/tests/convert/test_async.py b/tests/convert/test_async.py index be0ccb2..1d35970 100644 --- a/tests/convert/test_async.py +++ b/tests/convert/test_async.py @@ -2,9 +2,10 @@ import inspect import time +from collections.abc import AsyncGenerator, Generator from pathlib import Path from tempfile import TemporaryDirectory -from typing import Any, AsyncGenerator, Generator +from typing import Any import anyio import pytest diff --git a/tests/convert/test_sync.py b/tests/convert/test_sync.py index 35b632f..49a0260 100644 --- a/tests/convert/test_sync.py +++ b/tests/convert/test_sync.py @@ -1,7 +1,8 @@ from __future__ import annotations import inspect -from typing import Any, Coroutine, Generator, Generic +from collections.abc import Coroutine, Generator +from typing import Any, Generic import anyio import pytest diff --git a/tests/test_pipe.py b/tests/test_pipe.py index 3a542f7..18936a5 100644 --- a/tests/test_pipe.py +++ b/tests/test_pipe.py @@ -2,9 +2,10 @@ import inspect from collections import deque +from collections.abc import Awaitable from contextlib import suppress from functools import partial -from typing import Any, Awaitable, Callable +from typing import Any, Callable import anyio import pytest