Skip to content
Open
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
10 changes: 9 additions & 1 deletion a_sync/asyncio/create_task.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,16 @@ def create_task(
cdef object ccreate_task_simple(object coro):
return ccreate_task(coro, "", False, True)

cdef inline void _prune_persisted_tasks():
cdef object persisted
if _persisted_tasks:
for persisted in tuple(_persisted_tasks):
if persisted.done():
_persisted_task_callback(persisted)

cdef object ccreate_task(object coro, str name, bint skip_gc_until_done, bint log_destroy_pending):
cdef object loop = get_running_loop()
_prune_persisted_tasks()
cdef object task_factory = loop._task_factory
cdef object task, persisted

Expand Down Expand Up @@ -264,4 +272,4 @@ def _get_persisted_tasks() -> set[Task]:
# we can't import this directly to the .py test file
return _persisted_tasks

del Any, Awaitable, T
del Any, Awaitable, T
22 changes: 15 additions & 7 deletions a_sync/iter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ cdef class _ASyncFilter(_ASyncView):

@final
def __repr__(self) -> str:
return "<{type(self).__name__} for iterator={} function={} at {}>".format(
return "<{} for iterator={} function={} at {}>".format(
self.__wrapped__, self._function.__name__, hex(id(self))
)

Expand Down Expand Up @@ -860,16 +860,24 @@ cdef void _init_subclass(cls, dict kwargs):
cdef str type_string = ":obj:`T` objects"

cdef object base
cdef object bases
cdef object origin
cdef tuple args
cdef str module, qualname, name
for base in getattr(cls, "__orig_bases__", []):
if not hasattr(base, "__args__"):
bases = getattr(cls, "__orig_bases__", None)
if not bases:
bases = cls.__bases__
for base in bases:
origin = getattr(base, "__origin__", None)
if origin is None:
origin = base
if origin not in (ASyncIterable, ASyncIterator, ASyncFilter, ASyncSorter):
continue

args = get_args(base)
if base in (ASyncIterable, ASyncIterator, ASyncFilter, ASyncSorter):
raise Exception(base, args)
if not args:
args = getattr(base, "__args__", None) or ()

if args and not isinstance(type_argument := args[0], TypeVar):
module = getattr(type_argument, "__module__", "")
qualname = getattr(type_argument, "__qualname__", "")
Expand Down
Loading