Commit dae3da2
committed
prepare-sync: detect & warn on async user implementations
PR-C.3 review fixup. The opt-in-via-hasattr contract means
pyright doesn't catch a user signature mismatch when a developer
assumes "all observer methods are async" and defines
``async def prepare_sync(...)``. Today the call silently returns
an unawaited coroutine — the prep work never runs and Python
emits a delayed "coroutine was never awaited" RuntimeWarning at
GC time, breaking log correlation in a way that's hard to trace
back to the observer.
In ``_dispatch``, after each ``prepare_sync(event)`` returns,
check ``inspect.isawaitable(result)``. On hit: close the
awaitable (suppresses the secondary RuntimeWarning) and emit an
explicit ``warnings.warn`` naming the misconfiguration so it
fails loudly at the call site. Post-call detection catches the
common ``async def`` case AND the rarer
lambda-returning-coroutine / ``functools.partial``-of-async
cases — one check, all forms covered.1 parent 7e59ab9 commit dae3da2
1 file changed
Lines changed: 30 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
397 | 398 | | |
398 | 399 | | |
399 | 400 | | |
400 | | - | |
| 401 | + | |
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
405 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
406 | 435 | | |
407 | 436 | | |
408 | 437 | | |
| |||
0 commit comments