Skip to content

Commit

Permalink
Revert "feat: speed up SmartTask and SmartFuture init (#433)" (#435)
Browse files Browse the repository at this point in the history
* Revert "feat: speed up SmartTask and SmartFuture init (#433)"

This reverts commit 8bc2aba.

* feat(test): test SmartTask creation

* 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 23, 2024
1 parent 8bc2aba commit 8a8ee41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 2 additions & 7 deletions a_sync/_smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import asyncio
import contextvars
import logging
import warnings
import weakref
Expand Down Expand Up @@ -198,9 +197,7 @@ def __init__(
if key:
self._key = key
self._waiters = weakref.WeakSet()
self._callbacks.append(
(SmartFuture._self_done_cleanup_callback, contextvars.copy_context())
)
self.add_done_callback(SmartFuture._self_done_cleanup_callback)

def __repr__(self):
return f"<{type(self).__name__} key={self._key} waiters={self.num_waiters} {self._state}>"
Expand Down Expand Up @@ -301,9 +298,7 @@ def __init__(
"""
asyncio.Task.__init__(self, coro, loop=loop, name=name)
self._waiters: Set["asyncio.Task[T]"] = set()
self._callbacks.append(
(SmartTask._self_done_cleanup_callback, contextvars.copy_context())
)
self.add_done_callback(SmartTask._self_done_cleanup_callback)


def smart_task_factory(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_smart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import asyncio
import pytest

from a_sync._smart import SmartTask


@pytest.mark.asyncio_cooperative
async def test_smart_task_await():
await SmartTask(asyncio.sleep(0.1), loop=None)


@pytest.mark.asyncio_cooperative
async def test_smart_task_name():
t = SmartTask(asyncio.sleep(0.1), loop=None, name="test")
assert t.get_name() == "test"

0 comments on commit 8a8ee41

Please sign in to comment.