Skip to content

Commit

Permalink
fix: Rename pyproject.yaml to pyproject.toml (#453)
Browse files Browse the repository at this point in the history
* Rename pyproject.yaml to pyproject.toml

* chore: `black .`

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Nov 27, 2024
1 parent d557cbb commit 00f6605
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 592 deletions.
4 changes: 1 addition & 3 deletions a_sync/ENVIRONMENT_VARIABLES.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
:func:`DEBUG_MODE` for enabling debug mode on all classes.
"""

DEBUG_MODE = envs.create_env(
"DEBUG_MODE", bool, default=bool(DEBUG_CLASS_NAME), verbose=False
)
DEBUG_MODE = envs.create_env("DEBUG_MODE", bool, default=bool(DEBUG_CLASS_NAME), verbose=False)
"""bool: Enables debug mode on all classes.
Set this environment variable to `True` to enable debug mode on all classes.
Expand Down
4 changes: 1 addition & 3 deletions a_sync/_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ def __init__(
self.add_done_callback(SmartTask._self_done_cleanup_callback)


def smart_task_factory(
loop: asyncio.AbstractEventLoop, coro: Awaitable[T]
) -> SmartTask[T]:
def smart_task_factory(loop: asyncio.AbstractEventLoop, coro: Awaitable[T]) -> SmartTask[T]:
"""
Task factory function that an event loop calls to create new tasks.
Expand Down
34 changes: 17 additions & 17 deletions a_sync/a_sync/_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(
self.__wrapped__ = _fget
elif asyncio.iscoroutinefunction(_fget):
_validate_wrapped_fn(_fget)
self.__wrapped__: AsyncUnboundMethod[I, P, T] = (
self.modifiers.apply_async_modifiers(_fget)
self.__wrapped__: AsyncUnboundMethod[I, P, T] = self.modifiers.apply_async_modifiers(
_fget
)
else:
_validate_wrapped_fn(_fget)
Expand Down Expand Up @@ -264,9 +264,9 @@ def my_method(self, x):
result = await instance.my_method._all([1, 2, 3])
```
"""
return await self.map(
*instances, concurrency=concurrency, name=name, **kwargs
).all(pop=True, sync=False)
return await self.map(*instances, concurrency=concurrency, name=name, **kwargs).all(
pop=True, sync=False
)

async def _any(
self,
Expand Down Expand Up @@ -295,9 +295,9 @@ def my_method(self, x):
result = await instance.my_method._any([-1, 0, 1])
```
"""
return await self.map(
*instances, concurrency=concurrency, name=name, **kwargs
).any(pop=True, sync=False)
return await self.map(*instances, concurrency=concurrency, name=name, **kwargs).any(
pop=True, sync=False
)

async def _min(
self,
Expand Down Expand Up @@ -326,9 +326,9 @@ def my_method(self, x):
result = await instance.my_method._min([3, 1, 2])
```
"""
return await self.map(
*instances, concurrency=concurrency, name=name, **kwargs
).min(pop=True, sync=False)
return await self.map(*instances, concurrency=concurrency, name=name, **kwargs).min(
pop=True, sync=False
)

async def _max(
self,
Expand Down Expand Up @@ -357,9 +357,9 @@ def my_method(self, x):
result = await instance.my_method._max([3, 1, 2])
```
"""
return await self.map(
*instances, concurrency=concurrency, name=name, **kwargs
).max(pop=True, sync=False)
return await self.map(*instances, concurrency=concurrency, name=name, **kwargs).max(
pop=True, sync=False
)

async def _sum(
self,
Expand Down Expand Up @@ -388,9 +388,9 @@ def my_method(self, x):
result = await instance.my_method._sum([1, 2, 3])
```
"""
return await self.map(
*instances, concurrency=concurrency, name=name, **kwargs
).sum(pop=True, sync=False)
return await self.map(*instances, concurrency=concurrency, name=name, **kwargs).sum(
pop=True, sync=False
)

def __init_subclass__(cls) -> None:
for attr in cls.__dict__.values():
Expand Down
17 changes: 4 additions & 13 deletions a_sync/a_sync/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,14 @@ def __new__(cls, new_class_name, bases, attrs):
attr_name,
fn_modifiers,
)
if isinstance(
attr_value, (ASyncPropertyDescriptor, ASyncCachedPropertyDescriptor)
):
if isinstance(attr_value, (ASyncPropertyDescriptor, ASyncCachedPropertyDescriptor)):
# Wrap property
logger.debug("`%s is a property, now let's wrap it", attr_name)
logger.debug(
"since `%s` is a property, we will add a hidden dundermethod so you can still access it both sync and async",
attr_name,
)
attrs[attr_value.hidden_method_name] = (
attr_value.hidden_method_descriptor
)
attrs[attr_value.hidden_method_name] = attr_value.hidden_method_descriptor
logger.debug(
"`%s.%s` is now %s",
new_class_name,
Expand Down Expand Up @@ -178,9 +174,7 @@ class ASyncSingletonMeta(ASyncMeta):
- :class:`~a_sync.a_sync._meta.ASyncMeta`
"""

def __init__(
cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]
) -> None:
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()
Expand All @@ -203,10 +197,7 @@ def _update_logger(new_class_name: str) -> None:
Args:
new_class_name: The name of the new class being created.
"""
if (
ENVIRONMENT_VARIABLES.DEBUG_MODE
or ENVIRONMENT_VARIABLES.DEBUG_CLASS_NAME == new_class_name
):
if ENVIRONMENT_VARIABLES.DEBUG_MODE or ENVIRONMENT_VARIABLES.DEBUG_CLASS_NAME == new_class_name:
logger.addHandler(_debug_handler)
logger.setLevel(logging.DEBUG)
logger.info("debug mode activated")
Expand Down
8 changes: 2 additions & 6 deletions a_sync/a_sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ def get_default_executor() -> Executor:
return ProcessPoolExecutor(EXECUTOR_VALUE)
elif EXECUTOR_TYPE.lower().startswith("t"): # t, T, thread, THREADS, etc
return ThreadPoolExecutor(EXECUTOR_VALUE)
raise ValueError(
"Invalid value for A_SYNC_EXECUTOR_TYPE. Please use 'threads' or 'processes'."
)
raise ValueError("Invalid value for A_SYNC_EXECUTOR_TYPE. Please use 'threads' or 'processes'.")


default_sync_executor = get_default_executor()
Expand Down Expand Up @@ -154,9 +152,7 @@ def get_default_executor() -> Executor:
"""Sets the rate limit for function execution."""

SEMAPHORE = (
rpm
if (rpm := int(os.environ.get("A_SYNC_SEMAPHORE", 0)))
else null_modifiers["semaphore"]
rpm if (rpm := int(os.environ.get("A_SYNC_SEMAPHORE", 0))) else null_modifiers["semaphore"]
)
"""Sets the semaphore limit for function execution."""

Expand Down
20 changes: 5 additions & 15 deletions a_sync/a_sync/function.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ class ASyncFunction(_ModifiedMixin, Generic[P, T]):
"""

@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T:
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T:
"""
Calls the wrapped function synchronously.
Expand Down Expand Up @@ -417,9 +415,7 @@ class ASyncFunctionSyncDefault(ASyncFunction[P, T]):
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
) -> Coroutine[Any, Any, T]: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T: ...
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
Expand Down Expand Up @@ -458,9 +454,7 @@ class ASyncFunctionAsyncDefault(ASyncFunction[P, T]):
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
) -> Coroutine[Any, Any, T]: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T: ...
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
Expand All @@ -471,9 +465,7 @@ class ASyncFunctionAsyncDefault(ASyncFunction[P, T]):

class ASyncDecoratorSyncDefault(ASyncDecorator):
@overload
def __call__(
self, func: AnyFn[Concatenate[B, P], T]
) -> ASyncBoundMethodSyncDefault[P, T]:
def __call__(self, func: AnyFn[Concatenate[B, P], T]) -> ASyncBoundMethodSyncDefault[P, T]:
"""
Decorates a bound method with synchronous default behavior.
Expand Down Expand Up @@ -519,9 +511,7 @@ class ASyncDecoratorSyncDefault(ASyncDecorator):

class ASyncDecoratorAsyncDefault(ASyncDecorator):
@overload
def __call__(
self, func: AnyFn[Concatenate[B, P], T]
) -> ASyncBoundMethodAsyncDefault[P, T]:
def __call__(self, func: AnyFn[Concatenate[B, P], T]) -> ASyncBoundMethodAsyncDefault[P, T]:
"""
Decorates a bound method with asynchronous default behavior.
Expand Down
16 changes: 4 additions & 12 deletions a_sync/a_sync/method.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,7 @@ class ASyncMethodDescriptorAsyncDefault(ASyncMethodDescriptor[I, P, T]):
self, instance: None, owner: Type[I]
) -> ASyncMethodDescriptorAsyncDefault[I, P, T]: ...
@overload
def __get__(
self, instance: I, owner: Type[I]
) -> ASyncBoundMethodAsyncDefault[I, P, T]: ...
def __get__(self, instance: I, owner: Type[I]) -> ASyncBoundMethodAsyncDefault[I, P, T]: ...

class ASyncBoundMethod(ASyncFunction[P, T], Generic[I, P, T]):
"""
Expand Down Expand Up @@ -275,9 +273,7 @@ class ASyncBoundMethod(ASyncFunction[P, T], Generic[I, P, T]):
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
) -> Coroutine[Any, Any, T]: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T: ...
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
Expand Down Expand Up @@ -473,9 +469,7 @@ class ASyncBoundMethodSyncDefault(ASyncBoundMethod[I, P, T]):
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
) -> Coroutine[Any, Any, T]: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T: ...
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
Expand Down Expand Up @@ -518,9 +512,7 @@ class ASyncBoundMethodAsyncDefault(ASyncBoundMethod[I, P, T]):
self, *args: P.args, sync: Literal[False], **kwargs: P.kwargs
) -> Coroutine[Any, Any, T]: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs
) -> T: ...
def __call__(self, *args: P.args, asynchronous: Literal[False], **kwargs: P.kwargs) -> T: ...
@overload
def __call__(
self, *args: P.args, asynchronous: Literal[True], **kwargs: P.kwargs
Expand Down
4 changes: 1 addition & 3 deletions a_sync/a_sync/modifiers/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ def apply_async_cache(
# Validate
elif coro_fn is None:
if ram_cache_maxsize is not None and not isinstance(ram_cache_maxsize, int):
raise TypeError(
"'lru_cache_maxsize' must be an integer or None.", ram_cache_maxsize
)
raise TypeError("'lru_cache_maxsize' must be an integer or None.", ram_cache_maxsize)
elif not asyncio.iscoroutinefunction(coro_fn):
raise exceptions.FunctionNotAsync(coro_fn)

Expand Down
12 changes: 3 additions & 9 deletions a_sync/a_sync/modifiers/cache/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def apply_async_memory_cache(**kwargs: Unpack[CacheKwargs]) -> AsyncDecorator[P,


@overload
def apply_async_memory_cache(
coro_fn: int, **kwargs: Unpack[CacheKwargs]
) -> AsyncDecorator[P, T]:
def apply_async_memory_cache(coro_fn: int, **kwargs: Unpack[CacheKwargs]) -> AsyncDecorator[P, T]:
"""Creates a decorator with maxsize set by an integer.
This overload is used when an integer is provided as the coroutine function,
Expand All @@ -63,9 +61,7 @@ def apply_async_memory_cache(


@overload
def apply_async_memory_cache(
coro_fn: CoroFn[P, T], **kwargs: Unpack[CacheKwargs]
) -> CoroFn[P, T]:
def apply_async_memory_cache(coro_fn: CoroFn[P, T], **kwargs: Unpack[CacheKwargs]) -> CoroFn[P, T]:
"""
Applies an asynchronous LRU cache to a provided coroutine function.
Expand Down Expand Up @@ -158,9 +154,7 @@ def apply_async_memory_cache(
# Validate
elif coro_fn is None:
if maxsize not in [None, -1] and (not isinstance(maxsize, int) or maxsize <= 0):
raise TypeError(
"'lru_cache_maxsize' must be a positive integer or None.", maxsize
)
raise TypeError("'lru_cache_maxsize' must be a positive integer or None.", maxsize)

elif not asyncio.iscoroutinefunction(coro_fn):
raise exceptions.FunctionNotAsync(coro_fn)
Expand Down
4 changes: 1 addition & 3 deletions a_sync/a_sync/modifiers/limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def apply_rate_limit(
coro_fn = None

elif coro_fn is None:
if runs_per_minute is not None and not isinstance(
runs_per_minute, (int, AsyncLimiter)
):
if runs_per_minute is not None and not isinstance(runs_per_minute, (int, AsyncLimiter)):
raise TypeError("'runs_per_minute' must be an integer.", runs_per_minute)

elif not asyncio.iscoroutinefunction(coro_fn):
Expand Down
32 changes: 8 additions & 24 deletions a_sync/a_sync/property.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ class _ASyncPropertyDescriptorBase(ASyncDescriptor[I, Tuple[()], T]):
A TaskMapping object.
"""

class ASyncPropertyDescriptor(
_ASyncPropertyDescriptorBase[I, T], ap.base.AsyncPropertyDescriptor
):
class ASyncPropertyDescriptor(_ASyncPropertyDescriptorBase[I, T], ap.base.AsyncPropertyDescriptor):
"""Descriptor class for asynchronous properties."""

class property(ASyncPropertyDescriptor[I, T]):
Expand Down Expand Up @@ -169,21 +167,15 @@ def a_sync_property(
) -> ASyncPropertyDecoratorAsyncDefault[I, T]: ...
@overload
def a_sync_property(
func: AnyGetterFunction[I, T],
default: Literal["sync"],
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: Literal["sync"], **modifiers: Unpack[ModifierKwargs]
) -> ASyncPropertyDescriptorSyncDefault[I, T]: ...
@overload
def a_sync_property(
func: AnyGetterFunction[I, T],
default: Literal["async"],
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: Literal["async"], **modifiers: Unpack[ModifierKwargs]
) -> ASyncPropertyDescriptorAsyncDefault[I, T]: ...
@overload
def a_sync_property(
func: AnyGetterFunction[I, T],
default: DefaultMode = ...,
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: DefaultMode = ..., **modifiers: Unpack[ModifierKwargs]
) -> ASyncPropertyDescriptor[I, T]: ...

class ASyncCachedPropertyDescriptor(
Expand Down Expand Up @@ -269,9 +261,7 @@ class ASyncCachedPropertyDescriptorAsyncDefault(cached_property[I, T]):

default: Literal["async"]

ASyncCachedPropertyDecorator = Callable[
[AnyGetterFunction[I, T]], cached_property[I, T]
]
ASyncCachedPropertyDecorator = Callable[[AnyGetterFunction[I, T]], cached_property[I, T]]
ASyncCachedPropertyDecoratorSyncDefault = Callable[
[AnyGetterFunction[I, T]], ASyncCachedPropertyDescriptorSyncDefault[I, T]
]
Expand Down Expand Up @@ -309,21 +299,15 @@ def a_sync_cached_property(
) -> ASyncCachedPropertyDecoratorAsyncDefault[I, T]: ...
@overload
def a_sync_cached_property(
func: AnyGetterFunction[I, T],
default: Literal["sync"],
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: Literal["sync"], **modifiers: Unpack[ModifierKwargs]
) -> ASyncCachedPropertyDescriptorSyncDefault[I, T]: ...
@overload
def a_sync_cached_property(
func: AnyGetterFunction[I, T],
default: Literal["async"],
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: Literal["async"], **modifiers: Unpack[ModifierKwargs]
) -> ASyncCachedPropertyDescriptorAsyncDefault[I, T]: ...
@overload
def a_sync_cached_property(
func: AnyGetterFunction[I, T],
default: DefaultMode = ...,
**modifiers: Unpack[ModifierKwargs]
func: AnyGetterFunction[I, T], default: DefaultMode = ..., **modifiers: Unpack[ModifierKwargs]
) -> ASyncCachedPropertyDescriptor[I, T]: ...

class HiddenMethod(ASyncBoundMethodAsyncDefault[I, Tuple[()], T]):
Expand Down
Loading

0 comments on commit 00f6605

Please sign in to comment.