Bugfix iscoroutinefunction with Python3.7
See this Python bug https://bugs.python.org/issue33261. The iscoroutinefunction doesn't recognise partially wrapped coroutine functions as coroutine functions - which is problematic as the coroutines will be called as if they are sync, which results in un-awaited coroutines.
This commit is contained in:
parent
5f03ad3004
commit
6d5ccdefe2
1 changed files with 16 additions and 1 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
|
import functools
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import weakref
|
import weakref
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from inspect import iscoroutinefunction
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
|
|
||||||
|
|
@ -56,6 +57,20 @@ from .wrappers import Request
|
||||||
from .wrappers import Response
|
from .wrappers import Response
|
||||||
|
|
||||||
|
|
||||||
|
if sys.version_info >= (3, 8):
|
||||||
|
iscoroutinefunction = inspect.iscoroutinefunction
|
||||||
|
else:
|
||||||
|
|
||||||
|
def iscoroutinefunction(func):
|
||||||
|
while inspect.ismethod(func):
|
||||||
|
func = func.__func__
|
||||||
|
|
||||||
|
while isinstance(func, functools.partial):
|
||||||
|
func = func.func
|
||||||
|
|
||||||
|
return inspect.iscoroutinefunction(func)
|
||||||
|
|
||||||
|
|
||||||
def _make_timedelta(value):
|
def _make_timedelta(value):
|
||||||
if value is None or isinstance(value, timedelta):
|
if value is None or isinstance(value, timedelta):
|
||||||
return value
|
return value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue