fix(rtc): avoid deprecated asyncio.iscoroutinefunction in EventEmitter.on - #815
Merged
cloudwebrtc merged 1 commit intoSep 15, 2026
Merged
Conversation
xbt-a4224j
force-pushed
the
fix/event-emitter-iscoroutinefunction
branch
from
September 14, 2026 16:28
aa6fba4 to
1e80990
Compare
xbt-a4224j
marked this pull request as ready for review
September 14, 2026 16:50
xbt-a4224j
requested review from
cloudwebrtc,
lukasIO and
xianshijing-lk
as code owners
September 14, 2026 16:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #790
Problem
EventEmitter.on()callsasyncio.iscoroutinefunction()to reject coroutine callbacks. That function is deprecated in Python 3.14 and slated for removal in 3.16 (CPython gh-122858), so on 3.14 every callback registration emits aDeprecationWarning.Roomand friends register many handlers, so this is noisy in practice — the existing test suite alone produced 14 of them.Fix
inspect.iscoroutinefunction()is the documented replacement, but it is not a drop-in:asyncio.iscoroutinefunctionadditionally treats any callable tagged with the private sentinelasyncio.coroutines._is_coroutineas a coroutine function. On Python 3.9,inspect.iscoroutinefunction(AsyncMock())returnsFalse— a bare swap would let a mocked async callback past the guard, soemit()would call the mock and silently discard the unawaited coroutine.The fix keeps the sentinel check alongside
inspect.iscoroutinefunction, read withgetattr(..., None)so it degrades cleanly if the private attribute is removed in 3.16. Behaviour is identical toasyncio.iscoroutinefunctionon every supported version and the deprecated function is never called.Testing
Four tests added to
tests/rtc/test_emitter.py, all running on every version in the matrix:test_on_does_not_warn— promotesDeprecationWarningto an error around registration.test_on_rejects_async_callback—async defandfunctools.partial-wrapped.test_on_rejects_sentinel_tagged_callback— exercises the sentinel branch directly.test_on_rejects_async_mock— the real-world case; on 3.9 only the sentinel catches it.Verified as a real flip against the released
livekitwheel on all six supported Pythons (3.9–3.14): unpatched 1 failed / 7 passed / 14 warnings → patched 8 passed / 2 warnings.