Skip to content

Commit

Permalink
fix(docs): fix various crosslinks (#356)
Browse files Browse the repository at this point in the history
* 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] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Nov 15, 2024
1 parent 76e4e99 commit 5d848af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
18 changes: 8 additions & 10 deletions a_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -91,8 +91,6 @@
"all",
"any",
"as_yielded",
"exhaust_iterator",
"exhaust_iterators",
"map",
# classes
"ASyncIterable",
Expand Down
2 changes: 1 addition & 1 deletion a_sync/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions a_sync/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__())
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion a_sync/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down

0 comments on commit 5d848af

Please sign in to comment.