File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,11 @@ def _is_debug_mode():
19
19
20
20
def iscoroutinefunction (func ):
21
21
"""Return True if func is a decorated coroutine function."""
22
- return (inspect .iscoroutinefunction (func ) or
23
- getattr (func , '_is_coroutine' , None ) is _is_coroutine )
22
+ return (
23
+ inspect .iscoroutinefunction (func )
24
+ or getattr (func , '_is_coroutine' , None ) is _is_coroutine
25
+ or getattr (functools ._unwrap_partial (func ), "_is_coroutine" , None ) is _is_coroutine
26
+ )
24
27
25
28
26
29
# Prioritize native coroutine check to speed-up
Original file line number Diff line number Diff line change @@ -1644,9 +1644,27 @@ def fn1():
1644
1644
yield
1645
1645
self .assertFalse (asyncio .iscoroutinefunction (fn1 ))
1646
1646
1647
- async def fn2 ():
1647
+ def fn2 ():
1648
1648
pass
1649
+
1650
+ fn2 ._is_coroutine = asyncio .coroutines ._is_coroutine
1651
+
1649
1652
self .assertTrue (asyncio .iscoroutinefunction (fn2 ))
1653
+ self .assertTrue (asyncio .iscoroutinefunction (functools .partial (fn2 )))
1654
+ self .assertTrue (asyncio .iscoroutinefunction (functools .partial (functools .partial (fn2 ))))
1655
+
1656
+ async def async_fn ():
1657
+ pass
1658
+
1659
+ self .assertTrue (asyncio .iscoroutinefunction (afn2 ))
1660
+
1661
+ def sync_fn ():
1662
+ pass
1663
+
1664
+ partial_sync_fn = functools .partial (sync_fn )
1665
+ partial_sync_fn ._is_coroutine = asyncio .coroutines ._is_coroutine
1666
+
1667
+ self .assertTrue (asyncio .iscoroutinefunction (partial_sync_fn ))
1650
1668
1651
1669
self .assertFalse (asyncio .iscoroutinefunction (mock .Mock ()))
1652
1670
self .assertTrue (asyncio .iscoroutinefunction (mock .AsyncMock ()))
You can’t perform that action at this time.
0 commit comments