From 5d848af65dc0ae4534f21baa3313ccf040c9ad22 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:04:55 -0400 Subject: [PATCH] fix(docs): fix various crosslinks (#356) * fix(docs): fix a_sync module cross linking * chore: auto-update documentation a_sync/executor.py * fix(docs): fix SyncModeInAsyncContextError cross-links * chore: `black .` --------- Co-authored-by: github-actions[bot] --- a_sync/__init__.py | 18 ++++++++---------- a_sync/executor.py | 2 +- a_sync/iter.py | 16 ++++++++-------- a_sync/task.py | 3 ++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/a_sync/__init__.py b/a_sync/__init__.py index 789f92d2..68df91df 100644 --- a/a_sync/__init__.py +++ b/a_sync/__init__.py @@ -8,14 +8,14 @@ such as queues and locks, with extra functionality. Modules and components included: -- :mod:`~aliases`, :mod:`~exceptions`, :mod:`~iter`, :mod:`~task`: Core modules of the library. -- :class:`~ASyncGenericBase`, :class:`~ASyncGenericSingleton`, :func:`~a_sync`: Base classes and decorators for dual-context execution. -- :class:`~ASyncCachedPropertyDescriptor`, :class:`~ASyncPropertyDescriptor`, `cached_property`, `property`: Property descriptors for async properties. -- :func:`~as_completed`, :func:`~create_task`, :func:`~gather`: Enhanced asyncio functions. -- Executors: :class:`~AsyncThreadPoolExecutor`, :class:`~AsyncProcessPoolExecutor`, :class:`~PruningThreadPoolExecutor` for async execution. -- Iterators: :class:`~ASyncFilter`, :class:`~ASyncSorter`, :class:`~ASyncIterable`, :class:`~ASyncIterator` for async iteration. -- Utilities: :func:`~all`, :func:`~any`, :func:`~as_yielded`, :func:`~exhaust_iterator`, :func:`~exhaust_iterators` for async utilities. -- :func:`~apply_semaphore`: Function to apply semaphores to coroutines. + - :mod:`~a_sync.aliases`, :mod:`~a_sync.exceptions`, :mod:`~a_sync.iter`, :mod:`~a_sync.task`: Core modules of the library. + - :class:`~ASyncGenericBase`, :class:`~ASyncGenericSingleton`, :func:`~a_sync`: Base classes and decorators for dual-context execution. + - :class:`~ASyncCachedPropertyDescriptor`, :class:`~ASyncPropertyDescriptor`, `cached_property`, `property`: Property descriptors for async properties. + - :func:`~as_completed`, :func:`~create_task`, :func:`~gather`: Enhanced asyncio functions. + - Executors: :class:`~AsyncThreadPoolExecutor`, :class:`~AsyncProcessPoolExecutor`, :class:`~PruningThreadPoolExecutor` for async execution. + - Iterators: :class:`~ASyncIterable`, :class:`~ASyncIterator`, :class:`~filter`, :class:`~sorted` for async iteration. + - Utilities: :func:`~all`, :func:`~any`, :func:`~as_yielded` for async utilities. + - :func:`~a_sync.a_sync.modifiers.semaphores.apply_semaphore`: Function to apply semaphores to coroutines. Alias for backward compatibility: - :class:`~ASyncBase` is an alias for :class:`~ASyncGenericBase`, which will be removed eventually, probably in version 0.1.0. @@ -91,8 +91,6 @@ "all", "any", "as_yielded", - "exhaust_iterator", - "exhaust_iterators", "map", # classes "ASyncIterable", diff --git a/a_sync/executor.py b/a_sync/executor.py index 89893754..c0249fd0 100644 --- a/a_sync/executor.py +++ b/a_sync/executor.py @@ -8,7 +8,7 @@ Executor Classes: - :class:`AsyncProcessPoolExecutor`: A process pool executor providing asynchronous run and submit methods, with support for synchronous mode - :class:`AsyncThreadPoolExecutor`: A thread pool executor providing asynchronous run and submit methods, with support for synchronous mode - - :class:`PruningThreadPoolExecutor`: An :class:`ASyncThreadPoolExecutor` that prunes inactive threads after a timeout, ensuring at least one thread remains active to prevent locks. + - :class:`PruningThreadPoolExecutor`: An :class:`AsyncThreadPoolExecutor` that prunes inactive threads after a timeout, ensuring at least one thread remains active to prevent locks. See Also: - :mod:`concurrent.futures` for the original synchronous executor implementations. diff --git a/a_sync/iter.py b/a_sync/iter.py index 4511917c..01f0c671 100644 --- a/a_sync/iter.py +++ b/a_sync/iter.py @@ -136,7 +136,7 @@ class ASyncIterable(_AwaitableAsyncIterableMixin[T], Iterable[T]): note that synchronous iteration relies on the :class:`ASyncIterator` class, which uses `asyncio.get_event_loop().run_until_complete` to fetch items. This can raise a `RuntimeError` if the event loop is - already running, and in such cases, a :class:`SyncModeInAsyncContextError` + already running, and in such cases, a :class:`~a_sync.exceptions.SyncModeInAsyncContextError` is raised from the `RuntimeError`. Example: @@ -192,9 +192,9 @@ def __iter__(self) -> Iterator[T]: Note: Synchronous iteration leverages :class:`ASyncIterator`, which uses :meth:`asyncio.BaseEventLoop.run_until_complete` to fetch items. - :meth:`ASyncIterator.__next__` raises a :class:`SyncModeInAsyncContextError` if the event loop is already running. + :meth:`ASyncIterator.__next__` raises a :class:`~a_sync.exceptions.SyncModeInAsyncContextError` if the event loop is already running. - If you encounter a :class:`SyncModeInAsyncContextError`, you are likely working in an async codebase + If you encounter a :class:`~a_sync.exceptions.SyncModeInAsyncContextError`, you are likely working in an async codebase and should consider asynchronous iteration using :meth:`__aiter__` and :meth:`__anext__` instead. """ yield from ASyncIterator(self.__aiter__()) @@ -212,7 +212,7 @@ class ASyncIterator(_AwaitableAsyncIterableMixin[T], Iterator[T]): By implementing both `__next__` and `__anext__` methods, ASyncIterator enables objects to be iterated using standard iteration protocols while internally managing the complexities of asynchronous iteration. This design simplifies the use of asynchronous iterables in environments or frameworks that are not inherently asynchronous, such as standard synchronous functions or older codebases being gradually migrated to asynchronous IO. Note: - Synchronous iteration with `ASyncIterator` uses `asyncio.get_event_loop().run_until_complete`, which can raise a `RuntimeError` if the event loop is already running. In such cases, a :class:`SyncModeInAsyncContextError` is raised from the `RuntimeError`, indicating that synchronous iteration is not possible in an already running event loop. + Synchronous iteration with `ASyncIterator` uses `asyncio.get_event_loop().run_until_complete`, which can raise a `RuntimeError` if the event loop is already running. In such cases, a :class:`~a_sync.exceptions.SyncModeInAsyncContextError` is raised from the `RuntimeError`, indicating that synchronous iteration is not possible in an already running event loop. Example: >>> async_iterator = ASyncIterator(some_async_iterator) @@ -234,9 +234,9 @@ def __next__(self) -> T: Note: This method uses :meth:`asyncio.BaseEventLoop.run_until_complete` to fetch items. This raises a :class:`RuntimeError` if the event loop is already running. - This RuntimeError will be caught and a more descriptive :class:`SyncModeInAsyncContextError` will be raised in its place. + This RuntimeError will be caught and a more descriptive :class:`~a_sync.exceptions.SyncModeInAsyncContextError` will be raised in its place. - If you encounter a :class:`SyncModeInAsyncContextError`, you are likely working in an async codebase + If you encounter a :class:`~a_sync.exceptions.SyncModeInAsyncContextError`, you are likely working in an async codebase and should consider asynchronous iteration using :meth:`__aiter__` and :meth:`__anext__` instead. Raises: @@ -317,9 +317,9 @@ def __iter__(self) -> Self: Note: Synchronous iteration uses :meth:`asyncio.BaseEventLoop.run_until_complete` to fetch items. This raises a :class:`RuntimeError` if the event loop is already running. - This RuntimeError will be caught and a more descriptive :class:`SyncModeInAsyncContextError` will be raised in its place. + This RuntimeError will be caught and a more descriptive :class:`~a_sync.exceptions.SyncModeInAsyncContextError` will be raised in its place. - If you encounter a :class:`SyncModeInAsyncContextError`, you are likely working in an async codebase + If you encounter a :class:`~a_sync.exceptions.SyncModeInAsyncContextError`, you are likely working in an async codebase and should consider asynchronous iteration using :meth:`__aiter__` and :meth:`__anext__` instead. """ return self diff --git a/a_sync/task.py b/a_sync/task.py index ea08c476..c3026ba3 100644 --- a/a_sync/task.py +++ b/a_sync/task.py @@ -163,7 +163,8 @@ async def _wrapped_set_next( try: return await wrapped_func(*args, **kwargs) except exceptions.SyncModeInAsyncContextError as e: - raise Exception(e, self.__wrapped__) + e.args = *e.args, f"wrapped:{self.__wrapped__}" + raise except TypeError as e: if __a_sync_recursion > 2 or not ( str(e).startswith(wrapped_func.__name__)