Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions a_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,22 @@
from a_sync import aliases, exceptions, functools, iter, task
from a_sync.a_sync import ASyncGenericBase, ASyncGenericSingleton, a_sync
from a_sync.a_sync.modifiers.semaphores import apply_semaphore
from a_sync.a_sync.property import ASyncCachedPropertyDescriptor, ASyncPropertyDescriptor
from a_sync.a_sync.property import ASyncCachedPropertyDescriptor as cached_property
from a_sync.a_sync.property import ASyncCachedPropertyDescriptor
from a_sync.a_sync.property import \
ASyncCachedPropertyDescriptor as cached_property
from a_sync.a_sync.property import ASyncPropertyDescriptor
from a_sync.a_sync.property import ASyncPropertyDescriptor as property
from a_sync.asyncio import as_completed, create_task, gather, cgather, igather
from a_sync.executor import *
from a_sync.executor import AsyncThreadPoolExecutor as ThreadPoolExecutor
from a_sync.asyncio import as_completed, cgather, create_task, gather, igather
from a_sync.executor import AsyncProcessPoolExecutor as ProcessPoolExecutor
from a_sync.executor import AsyncThreadPoolExecutor as ThreadPoolExecutor
from a_sync.executor import *
from a_sync.future import ASyncFuture, future # type: ignore [attr-defined]
from a_sync.iter import ASyncFilter as filter
from a_sync.iter import ASyncSorter as sorted
from a_sync.iter import ASyncIterable, ASyncIterator
from a_sync.iter import ASyncSorter as sorted
from a_sync.primitives import *
from a_sync.task import TaskMapping as map
from a_sync.task import TaskMapping
from a_sync.task import TaskMapping as map
from a_sync.utils import all, any, as_yielded

# I alias the aliases for your convenience.
Expand Down Expand Up @@ -135,6 +137,7 @@
def _patch_async_property() -> None:
import async_property.base as base
import async_property.cached as cached

from a_sync.async_property.proxy import AwaitableOnly, AwaitableProxy

base.AwaitableOnly = AwaitableOnly
Expand Down
3 changes: 2 additions & 1 deletion a_sync/_smart.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asyncio import AbstractEventLoop, Future, Task
from typing import TYPE_CHECKING, Any, Awaitable, Generic, Optional, Tuple, TypeVar, Union
from typing import (TYPE_CHECKING, Any, Awaitable, Generic, Optional, Tuple,
TypeVar, Union)
from weakref import WeakSet

if TYPE_CHECKING:
Expand Down
54 changes: 12 additions & 42 deletions a_sync/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,14 @@ def sync_function(x: int) -> str:
"""

import asyncio
from collections.abc import (AsyncIterable, Awaitable, Callable, Coroutine,
Iterable)
from concurrent.futures._base import Executor
from decimal import Decimal
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Coroutine,
DefaultDict,
Deque,
Dict,
Generator,
Generic,
ItemsView,
Iterable,
Iterator,
KeysView,
List,
Literal,
Mapping,
NoReturn,
Optional,
Protocol,
Set,
Tuple,
Type,
TypedDict,
TypeVar,
Union,
ValuesView,
overload,
runtime_checkable,
)

from typing_extensions import Concatenate, ParamSpec, Self, Unpack
from typing import (TYPE_CHECKING, Any, Literal, Optional, Protocol, TypedDict,
TypeVar, Union, runtime_checkable)

from typing_extensions import ParamSpec

if TYPE_CHECKING:
from a_sync import ASyncGenericBase
Expand All @@ -118,7 +88,7 @@ def sync_function(x: int) -> str:
"""A :class:`TypeVar` that is used to represent instances of a common class."""

E = TypeVar("E", bound=Exception)
TYPE = TypeVar("TYPE", bound=Type)
TYPE = TypeVar("TYPE", bound=type)

P = ParamSpec("P")
"""A :class:`ParamSpec` used everywhere in the lib."""
Expand Down Expand Up @@ -189,7 +159,7 @@ class AsyncUnboundMethod(Protocol[I, P, T]):
It's essentially the function object itself, before it's accessed through an instance.
"""

__get__: Callable[[I, Type], CoroBoundMethod[I, P, T]]
__get__: Callable[[I, type], CoroBoundMethod[I, P, T]]


@runtime_checkable
Expand All @@ -201,7 +171,7 @@ class SyncUnboundMethod(Protocol[I, P, T]):
It's essentially the function object itself, before it's accessed through an instance.
"""

__get__: Callable[[I, Type], SyncBoundMethod[I, P, T]]
__get__: Callable[[I, type], SyncBoundMethod[I, P, T]]


AnyUnboundMethod = Union[AsyncUnboundMethod[I, P, T], SyncUnboundMethod[I, P, T]]
Expand Down Expand Up @@ -240,9 +210,9 @@ class ModifierKwargs(TypedDict, total=False):
default: DefaultMode
cache_type: CacheType
cache_typed: bool
ram_cache_maxsize: Optional[int]
ram_cache_ttl: Optional[Numeric]
runs_per_minute: Optional[int]
ram_cache_maxsize: int | None
ram_cache_ttl: Numeric | None
runs_per_minute: int | None
semaphore: SemaphoreSpec
# sync modifiers
executor: Executor
Expand Down
33 changes: 13 additions & 20 deletions a_sync/a_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,21 @@

from a_sync.a_sync.base import ASyncGenericBase
from a_sync.a_sync.decorator import a_sync
from a_sync.a_sync.function import (
ASyncFunction,
ASyncFunctionAsyncDefault,
ASyncFunctionSyncDefault,
)
from a_sync.a_sync.property import (
ASyncCachedPropertyDescriptor,
ASyncCachedPropertyDescriptorAsyncDefault,
ASyncCachedPropertyDescriptorSyncDefault,
ASyncPropertyDescriptor,
ASyncPropertyDescriptorAsyncDefault,
ASyncPropertyDescriptorSyncDefault,
HiddenMethod,
HiddenMethodDescriptor,
)
from a_sync.a_sync.property import ASyncCachedPropertyDescriptor as cached_property
from a_sync.a_sync.property import ASyncPropertyDescriptor as property
from a_sync.a_sync.singleton import ASyncGenericSingleton

from a_sync.a_sync.function import (ASyncFunction, ASyncFunctionAsyncDefault,
ASyncFunctionSyncDefault)
# NOTE: We purposely import this without including in __all__. Do not remove.
from a_sync.a_sync.modifiers.semaphores import apply_semaphore

from a_sync.a_sync.property import ASyncCachedPropertyDescriptor
from a_sync.a_sync.property import \
ASyncCachedPropertyDescriptor as cached_property
from a_sync.a_sync.property import (ASyncCachedPropertyDescriptorAsyncDefault,
ASyncCachedPropertyDescriptorSyncDefault)
from a_sync.a_sync.property import ASyncPropertyDescriptor
from a_sync.a_sync.property import ASyncPropertyDescriptor as property
from a_sync.a_sync.property import (ASyncPropertyDescriptorAsyncDefault,
ASyncPropertyDescriptorSyncDefault,
HiddenMethod, HiddenMethodDescriptor)
from a_sync.a_sync.singleton import ASyncGenericSingleton

__all__ = [
# entrypoints
Expand Down
14 changes: 4 additions & 10 deletions a_sync/a_sync/_descriptor.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from a_sync._typing import *
from a_sync import TaskMapping
from a_sync._typing import *
from a_sync.a_sync import decorator
from a_sync.a_sync.function import (
ASyncFunction,
ModifierManager,
_ModifiedMixin,
)
from a_sync.functools import (
cached_property_unsafe,
update_wrapper,
)
from a_sync.a_sync.function import (ASyncFunction, ModifierManager,
_ModifiedMixin)
from a_sync.functools import cached_property_unsafe, update_wrapper

class ASyncDescriptor(_ModifiedMixin, Generic[I, P, T]):
__wrapped__: AnyFn[Concatenate[I, P], T]
Expand Down
4 changes: 3 additions & 1 deletion a_sync/a_sync/_descriptor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import asyncio
from a_sync._typing import *
from a_sync.a_sync import decorator
from a_sync.a_sync.function import ASyncFunction
from a_sync.a_sync.function cimport _ASyncFunction, _ModifiedMixin, _validate_wrapped_fn

from a_sync.a_sync.function cimport (_ASyncFunction, _ModifiedMixin,
_validate_wrapped_fn)
from a_sync.a_sync.modifiers.manager cimport ModifierManager
from a_sync.functools cimport cached_property_unsafe, update_wrapper

Expand Down
2 changes: 1 addition & 1 deletion a_sync/a_sync/_helpers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ This module provides utility functions for handling asynchronous operations
and converting synchronous functions to asynchronous ones.
"""

from a_sync._typing import *
from a_sync import exceptions as exceptions
from a_sync._typing import *

def get_event_loop() -> asyncio.AbstractEventLoop: ...
def _await(awaitable: Awaitable[T]) -> T: ...
2 changes: 2 additions & 0 deletions a_sync/a_sync/_kwargs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ This module provides utility functions for handling keyword arguments related to
"""

from a_sync import exceptions

from a_sync.a_sync._flags cimport validate_and_negate_if_necessary
from a_sync.a_sync.flags cimport VIABLE_FLAGS


# cdef exceptions
cdef object TooManyFlags = exceptions.TooManyFlags
del exceptions
Expand Down
14 changes: 6 additions & 8 deletions a_sync/a_sync/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
import threading
from abc import ABCMeta
from inspect import isasyncgenfunction
from typing import Any, Dict, Tuple
from typing import Any

from a_sync import ENVIRONMENT_VARIABLES
from a_sync.a_sync import modifiers
from a_sync.a_sync.function import _ASyncFunction, _ModifiedMixin
from a_sync.a_sync.method import ASyncMethodDescriptor
from a_sync.a_sync.property import (
ASyncCachedPropertyDescriptor,
ASyncPropertyDescriptor,
)
from a_sync.a_sync.property import (ASyncCachedPropertyDescriptor,
ASyncPropertyDescriptor)
from a_sync.future import _ASyncFutureWrappedFn # type: ignore [attr-defined]
from a_sync.iter import ASyncGeneratorFunction
from a_sync.primitives.locks.semaphore import Semaphore
Expand Down Expand Up @@ -152,7 +150,7 @@ def __new__(cls, new_class_name, bases, attrs):
new_class_name,
attr_name,
)
return super(ASyncMeta, cls).__new__(cls, new_class_name, bases, attrs)
return super().__new__(cls, new_class_name, bases, attrs)


class ASyncSingletonMeta(ASyncMeta):
Expand All @@ -174,8 +172,8 @@ class ASyncSingletonMeta(ASyncMeta):
- :class:`~a_sync.a_sync._meta.ASyncMeta`
"""

def __init__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> None:
cls.__instances: Dict[bool, object] = {}
def __init__(cls, name: str, bases: tuple[type, ...], namespace: dict[str, Any]) -> None:
cls.__instances: dict[bool, object] = {}
"""Dictionary to store singleton instances."""
cls.__lock = threading.Lock()
"""Lock to ensure thread-safe instance creation."""
Expand Down
3 changes: 2 additions & 1 deletion a_sync/a_sync/abstract.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ Note: It is recommended to use :class:`ASyncGenericBase` for most use cases. Thi
is intended for more custom implementations if necessary.
"""

from a_sync._typing import *
import abc
import functools
import logging

from a_sync import exceptions as exceptions
from a_sync._typing import *
from a_sync.a_sync import modifiers as modifiers
from a_sync.a_sync._meta import ASyncMeta as ASyncMeta
from a_sync.exceptions import NoFlagsFound as NoFlagsFound
Expand Down
6 changes: 4 additions & 2 deletions a_sync/a_sync/abstract.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ is intended for more custom implementations if necessary.

from abc import abstractmethod
from logging import getLogger
from typing import Dict, Any, Tuple
from typing import Any, Dict, Tuple

from a_sync._typing import *
from a_sync.a_sync._kwargs cimport get_flag_name, is_sync

from a_sync.a_sync._flags cimport validate_and_negate_if_necessary
from a_sync.a_sync._kwargs cimport get_flag_name, is_sync

from a_sync.a_sync._meta import ASyncMeta


Expand Down
3 changes: 2 additions & 1 deletion a_sync/a_sync/base.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from a_sync._typing import *
import functools
import logging

from a_sync import exceptions as exceptions
from a_sync._typing import *
from a_sync.a_sync.abstract import ASyncABC as ASyncABC
from a_sync.a_sync.flags import VIABLE_FLAGS as VIABLE_FLAGS

Expand Down
11 changes: 9 additions & 2 deletions a_sync/a_sync/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ from cpython.object cimport Py_TYPE, PyObject
from cpython.tuple cimport PyTuple_GET_SIZE, PyTuple_GetItem

from a_sync._typing import *
from a_sync.a_sync._flags cimport validate_and_negate_if_necessary, validate_flag_value

from a_sync.a_sync._flags cimport (validate_and_negate_if_necessary,
validate_flag_value)

from a_sync.a_sync.abstract import ASyncABC

from a_sync.a_sync.flags cimport VIABLE_FLAGS
from a_sync.exceptions import ASyncFlagException, FlagNotDefined, InvalidFlag, NoFlagsFound, TooManyFlags

from a_sync.exceptions import (ASyncFlagException, FlagNotDefined, InvalidFlag,
NoFlagsFound, TooManyFlags)

from a_sync.functools cimport cached_property_unsafe


Expand Down
2 changes: 1 addition & 1 deletion a_sync/a_sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from concurrent.futures._base import Executor

from a_sync._typing import *
from a_sync._typing import CacheType, DefaultMode, ModifierKwargs

EXECUTOR_TYPE = os.environ.get("A_SYNC_EXECUTOR_TYPE", "threads")
"""Specifies the type of executor to use.
Expand Down
17 changes: 8 additions & 9 deletions a_sync/a_sync/decorator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# mypy: disable-error-code=valid-type
# mypy: disable-error-code=misc
from concurrent.futures import Executor
from a_sync._typing import *

from a_sync._typing import (AnyFn, CoroFn, DefaultMode, Literal,
ModifierKwargs, Optional, P, SyncFn, T, Union,
Unpack, overload)
from a_sync.a_sync import config
from a_sync.a_sync.function import (
ASyncDecorator,
ASyncFunction,
ASyncDecoratorAsyncDefault,
ASyncDecoratorSyncDefault,
ASyncFunctionAsyncDefault,
ASyncFunctionSyncDefault,
)
from a_sync.a_sync.function import (ASyncDecorator, ASyncDecoratorAsyncDefault,
ASyncDecoratorSyncDefault, ASyncFunction,
ASyncFunctionAsyncDefault,
ASyncFunctionSyncDefault)

########################
# The a_sync decorator #
Expand Down
1 change: 1 addition & 0 deletions a_sync/a_sync/function.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from a_sync.a_sync.modifiers.manager cimport ModifierManager


cdef class _ModifiedMixin:
cdef readonly ModifierManager modifiers
cdef public object __wrapped__
Expand Down
9 changes: 4 additions & 5 deletions a_sync/a_sync/function.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import functools
from logging import Logger
from typing import Any

from a_sync import TaskMapping
from a_sync._typing import *
from a_sync.a_sync.method import (
ASyncBoundMethod,
ASyncBoundMethodAsyncDefault,
ASyncBoundMethodSyncDefault,
)
from a_sync.a_sync.method import (ASyncBoundMethod,
ASyncBoundMethodAsyncDefault,
ASyncBoundMethodSyncDefault)
from a_sync.a_sync.modifiers.manager import ModifierManager

logger: Logger
Expand Down
Loading