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
1 change: 1 addition & 0 deletions newsfragments/159.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow ``loop.call_later()`` to accept negative delays, matching asyncio's behavior by scheduling the callback immediately.
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ def skip(rel_id):
item.add_marker(pytest.mark.skip)

if sys.version_info >= (3, 11):
# CPython's SSLProtocol test intentionally leaves the two transports
# created while checking the missing-server_hostname warning without
# cleanup callbacks. pytest 9 reports their finalizer warnings as
# unraisable exceptions, even though the test itself passes.
mark(
pytest.mark.filterwarnings("ignore:.*_SSLProtocolTransport.__del__.*"),
"test_sslproto.py::SslProtoHandshakeTests::"
"test_check_hostname_requires_server_hostname",
may_be_absent=True,
)

# This tries to use a mock ChildWatcher that does something unlikely.
# We don't support it because we don't actually use the ChildWatcher
# to manage subprocesses.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ async def cancel_sleep():
await trio_asyncio.aio_as_trio(cancel_sleep, loop=loop)()
assert owch == 0

@pytest.mark.trio
async def test_call_later_accepts_negative_delay(self, loop):
called = trio.Event()

def callback():
called.set()

loop.call_later(-1, callback)
await called.wait()


@pytest.mark.trio
async def test_wrong_context_manager_order():
Expand Down
1 change: 0 additions & 1 deletion trio_asyncio/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def call_later(self, delay, callback, *args, **context):
:return: a handle which may be used to cancel the timer.
"""
self._check_callback(callback, "call_later")
assert delay >= 0, delay
h = asyncio.TimerHandle(delay + self.time(), callback, args, self, **context)
self._queue_handle(h)
return h
Expand Down
Loading