Python: Replace deprecated asyncio.iscoroutinefunction with inspect.iscoroutinefunction#4552
Conversation
…scoroutinefunction Fixes microsoft#4522. asyncio.iscoroutinefunction() is deprecated since Python 3.14. Replaced all remaining usages in test files with inspect.iscoroutinefunction().
There was a problem hiding this comment.
Pull request overview
Updates Python test suites to avoid the deprecated asyncio.iscoroutinefunction() (deprecated in Python 3.14) by switching to inspect.iscoroutinefunction(), aligning tests with existing production-code behavior.
Changes:
- Replaced
asyncio.iscoroutinefunction()withinspect.iscoroutinefunction()in core workflow tests. - Replaced
asyncio.iscoroutinefunction()withinspect.iscoroutinefunction()in DevUI cleanup hook tests. - Updated imports and one test docstring to reflect
inspectusage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/core/tests/workflow/test_function_executor.py | Switches coroutine-function detection in a staticmethod-descriptor behavior test to use inspect.iscoroutinefunction(). |
| python/packages/devui/tests/devui/test_cleanup_hooks.py | Switches coroutine-function detection when executing cleanup hooks to use inspect.iscoroutinefunction() and adds the corresponding import. |
You can also share your feedback on Copilot code review. Take the survey.
| """Tests for cleanup hook registration and execution.""" | ||
|
|
||
| import asyncio | ||
| import inspect |
There was a problem hiding this comment.
inspect is now imported at module scope; the additional import inspect statements inside individual tests are redundant. Consider removing the inner imports to keep imports consistent and avoid duplication.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
@copilot open a new pull request to apply changes based on the comments in this thread |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Summary
asyncio.iscoroutinefunction()calls withinspect.iscoroutinefunction()in test filesasyncio.iscoroutinefunction()is deprecated since Python 3.14inspect.iscoroutinefunction()— only test files had the deprecated usageFixes #4522
Changes
python/packages/core/tests/workflow/test_function_executor.py— replaced 3 usages, addedimport inspectpython/packages/devui/tests/devui/test_cleanup_hooks.py— replaced 1 usage, addedimport inspectTest plan
asyncio.iscoroutinefunctionusages remain in codebase