Skip to content

Commit

Permalink
feat: skip boundscheck
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Dec 12, 2024
1 parent e924e46 commit e635a66
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
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

0 comments on commit e635a66

Please sign in to comment.