From afb0b06067f67a60242f004f587dca32b3c81593 Mon Sep 17 00:00:00 2001 From: Jens Jorgensen Date: Wed, 22 Oct 2025 07:32:38 -0500 Subject: [PATCH 1/2] call_later should always return TimerHandle --- tests/test_base.py | 6 ++++++ uvloop/loop.pyx | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index 89a82fe4..3eddbe50 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -938,6 +938,12 @@ def test_loop_call_later_handle_when_after_fired(self): self.loop.run_until_complete(fut) self.assertEqual(handle.when(), when) + def test_loop_call_later_0_returns_timer_handle(self): + cb = lambda: False # NoQA + handle = self.loop.call_later(0, cb) + handle.when() # undesired behavior: handle is a Handle instead of TimerHandle + handle.cancel() + class TestBaseAIO(_TestBase, AIOTestCase): pass diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index 2ed1f272..ea4e1d38 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -1326,10 +1326,7 @@ cdef class Loop: when = round(delay * 1000) if not args: args = None - if when == 0: - return self._call_soon(callback, args, context) - else: - return self._call_later(when, callback, args, context) + return self._call_later(when, callback, args, context) def call_at(self, when, callback, *args, context=None): """Like call_later(), but uses an absolute time. From f2ec97f752c1ede9ae0be4ffb6fc46f46b09eabd Mon Sep 17 00:00:00 2001 From: Jens Jorgensen Date: Wed, 22 Oct 2025 07:46:12 -0500 Subject: [PATCH 2/2] fix flake8 issues --- tests/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_base.py b/tests/test_base.py index 3eddbe50..745e7cb7 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -941,7 +941,7 @@ def test_loop_call_later_handle_when_after_fired(self): def test_loop_call_later_0_returns_timer_handle(self): cb = lambda: False # NoQA handle = self.loop.call_later(0, cb) - handle.when() # undesired behavior: handle is a Handle instead of TimerHandle + handle.when() handle.cancel()