Use asyncio.iscoroutine instead of inspect.isawaitable #74
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.
R.e. the performance issues seen here: #54
Long term, it seems the best fix would be to minimize the usage of
iscoroutine
, in favor of inspecting and caching whether or not the functioniscoroutinefunction
.As a shorter term fix, this change switches form
inspect.isawaitable
toasyncio.iscoroutine
.inspect.isawaitable
is pure Python, while asyncio.iscoroutine is optimized in C and has a smarter type-cache. Reading through their implementations and comments, it isn't clear to me whether or not there is a semantic difference between the two, I'm relying on integration tests here to catch that. If there is a difference, I can update to use an early-exitingor
to at least take the fast path when possible, assuming standard coroutines are the common case 🤞