Skip to content

Commit

Permalink
chore: refactor TypeVars (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Feb 11, 2024
1 parent c73e245 commit 168eeae
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 31 deletions.
14 changes: 10 additions & 4 deletions a_sync/_typing.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@

import asyncio
from concurrent.futures._base import Executor
from typing import (TYPE_CHECKING, Any, Awaitable, Callable, DefaultDict, Dict,
Generic, Iterator, List, Literal, Optional, Tuple,
Type, TypedDict, TypeVar, Union, overload)
from decimal import Decimal
from typing import (TYPE_CHECKING, Any, AsyncIterable, AsyncIterator, Awaitable,
Callable, DefaultDict, Dict, Generic, Iterable, Iterator,
List, Literal, Optional, Set, Tuple, Type, TypedDict, TypeVar,
Union, final, overload)

from typing_extensions import Concatenate, ParamSpec, Unpack
from typing_extensions import Concatenate, ParamSpec, Self, Unpack

if TYPE_CHECKING:
from a_sync.abstract import ASyncABC

T = TypeVar("T")
K = TypeVar("K")
V = TypeVar("V")
P = ParamSpec("P")

MaybeAwaitable = Union[Awaitable[T], T]
Expand Down Expand Up @@ -46,3 +50,5 @@ class ModifierKwargs(TypedDict, total=False):
semaphore: SemaphoreSpec
# sync modifiers
executor: Executor

AnyIterable = Union[AsyncIterable[K], Iterable[K]]
10 changes: 1 addition & 9 deletions a_sync/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

import asyncio
import concurrent.futures
from decimal import Decimal
from functools import partial, wraps
from inspect import isawaitable
from typing import (Any, Awaitable, Callable, Generic, List, Optional, Set,
TypeVar, Union, final, overload)

from typing_extensions import ParamSpec, Self, Unpack
from a_sync._typing import *

from a_sync._typing import ModifierKwargs

T = TypeVar('T')
P = ParamSpec('P')
MaybeAwaitable = Union[T, Awaitable[T]]

def future(callable: Union[Callable[P, Awaitable[T]], Callable[P, T]] = None, **kwargs: Unpack[ModifierKwargs]) -> Callable[P, Union[T, "ASyncFuture[T]"]]:
return _ASyncFutureWrappedFn(callable, **kwargs)
Expand Down
3 changes: 1 addition & 2 deletions a_sync/iter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

import asyncio
from typing import AsyncIterable, AsyncIterator, Iterable, Iterator, TypeVar
from a_sync._typing import *

T = TypeVar('T')

class ASyncIterable(AsyncIterable[T], Iterable[T]):
"""An abstract iterable implementation that can be used in both a `for` loop and an `async for` loop."""
Expand Down
2 changes: 1 addition & 1 deletion a_sync/modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import functools
import sys

from a_sync import _helpers, _kwargs, exceptions
from a_sync import _helpers, _kwargs
from a_sync._typing import *
from a_sync.modifiers.manager import ModifierManager

Expand Down
9 changes: 2 additions & 7 deletions a_sync/primitives/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
import weakref
from concurrent.futures import _base, thread
from functools import cached_property
from typing import Any, Callable, Optional, Tuple, TypeVar

from typing_extensions import ParamSpec

from a_sync._typing import *
from a_sync.primitives._debug import _DebugDaemonMixin

TEN_MINUTES = 60 * 10

T = TypeVar('T')
P = ParamSpec('P')

TEN_MINUTES = 60 * 10

class _AsyncExecutorMixin(cf.Executor, _DebugDaemonMixin):
_max_workers: int
Expand Down
7 changes: 1 addition & 6 deletions a_sync/primitives/locks/semaphore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import logging
from collections import defaultdict
from threading import Thread, current_thread
from typing import Callable, Literal, Optional, TypeVar

from typing_extensions import ParamSpec

from a_sync._typing import *
from a_sync.primitives._debug import _DebugDaemonMixin

logger = logging.getLogger(__name__)

T = TypeVar('T')
P = ParamSpec('P')

class Semaphore(asyncio.Semaphore, _DebugDaemonMixin):
def __init__(self, value: int, name=None, **kwargs) -> None:
"""
Expand Down
3 changes: 1 addition & 2 deletions a_sync/primitives/queue.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio
import sys
from typing import Generic, List, TypeVar, Union, overload

T = TypeVar('T')
from a_sync._typing import *

if sys.version_info < (3, 9):
bases = (asyncio.Queue, Generic[T])
Expand Down

0 comments on commit 168eeae

Please sign in to comment.