Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip boundscheck #474

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
1 change: 1 addition & 0 deletions a_sync/a_sync/_kwargs.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
"""
This module provides utility functions for handling keyword arguments related to synchronous and asynchronous flags.
"""
Expand Down
3 changes: 2 additions & 1 deletion a_sync/a_sync/base.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
import functools
import inspect
from contextlib import suppress
Expand Down Expand Up @@ -192,7 +193,7 @@ cdef str _parse_flag_name_from_list(object cls, object items):
cdef str flag
cdef list[str] present_flags = [flag for flag in VIABLE_FLAGS if flag in items]
if not present_flags:
c_logger.debug("There are too many flags defined on %s", cls)
c_logger.debug("There are no flags defined on %s", cls)
raise exceptions.NoFlagsFound(cls, items.keys())
if len(present_flags) > 1:
c_logger.debug("There are too many flags defined on %s", cls)
Expand Down
34 changes: 15 additions & 19 deletions a_sync/asyncio/gather.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
"""
This module provides an enhanced version of :func:`asyncio.gather`.
"""
Expand Down Expand Up @@ -126,31 +127,25 @@ async def gather(
See Also:
:func:`asyncio.gather`
"""
is_mapping = _is_mapping(awaitables)
results = await (
gather_mapping(
if is_mapping := _is_mapping(awaitables):
results = await gather_mapping(
awaitables[0],
return_exceptions=return_exceptions,
exclude_if=exclude_if,
tqdm=tqdm,
**tqdm_kwargs,
)
if is_mapping
else (
tqdm_asyncio.gather(
*(
(_exc_wrap(a) for a in awaitables)
if return_exceptions
else awaitables
),
**tqdm_kwargs,
)
if tqdm
else asyncio.gather(*awaitables, return_exceptions=return_exceptions)
) # type: ignore [arg-type]
)
elif tqdm:
results = await tqdm_asyncio.gather(
*((_exc_wrap(a) for a in awaitables) if return_exceptions else awaitables),
**tqdm_kwargs,
)
else:
results = await asyncio.gather(*awaitables, return_exceptions=return_exceptions)

if exclude_if and not is_mapping:
results = [r for r in results if not exclude_if(r)]
return [r for r in results if not exclude_if(r)]

return results


Expand Down Expand Up @@ -199,7 +194,8 @@ async def gather_mapping(
# return data in same order as input mapping
return {k: results[k] for k in mapping}

cdef inline bint _is_mapping(object awaitables):

cdef inline bint _is_mapping(tuple awaitables):
return len(awaitables) == 1 and isinstance(awaitables[0], Mapping)


Expand Down
8 changes: 4 additions & 4 deletions a_sync/iter.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
import asyncio
import functools
import inspect
Expand Down Expand Up @@ -115,16 +116,15 @@ class _AwaitableAsyncIterableMixin(AsyncIterable[T]):
cdef object type_argument = T # Default value
cdef str type_string = ":obj:`T` objects"

cdef object base, args
cdef object base
cdef tuple args
cdef str module, qualname, name
for base in getattr(cls, "__orig_bases__", []):
if not hasattr(base, "__args__"):
continue

args = get_args(base)
if args and not isinstance(args[0], TypeVar):
type_argument = args[0]

if args and not isinstance(type_argument := args[0], TypeVar):
module = getattr(type_argument, "__module__", "")
qualname = getattr(type_argument, "__qualname__", "")
name = getattr(type_argument, "__name__", "")
Expand Down
1 change: 1 addition & 0 deletions a_sync/primitives/_loggable.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
"""
This module provides a mixin class to add debug logging capabilities to other classes.
"""
Expand Down
1 change: 1 addition & 0 deletions a_sync/primitives/locks/event.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
"""
This module provides an enhanced version of asyncio.Event with additional debug logging to help detect deadlocks.
"""
Expand Down
1 change: 1 addition & 0 deletions a_sync/primitives/locks/prio_semaphore.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cython: boundscheck=False
"""
This module provides priority-based semaphore implementations. These semaphores allow
waiters to be assigned priorities, ensuring that higher priority waiters are
Expand Down
Loading