37
37
import inspect
38
38
import operator
39
39
import itertools
40
+ import functools
40
41
from contextlib import _GeneratorContextManager
41
42
from inspect import getfullargspec , iscoroutinefunction , isgeneratorfunction
42
43
@@ -71,7 +72,7 @@ def __init__(self, func=None, name=None, signature=None,
71
72
self .name = '_lambda_'
72
73
self .doc = func .__doc__
73
74
self .module = func .__module__
74
- if inspect .isroutine (func ):
75
+ if inspect .isroutine (func ) or isinstance ( func , functools . partial ) :
75
76
argspec = getfullargspec (func )
76
77
self .annotations = getattr (func , '__annotations__' , {})
77
78
for a in ('args' , 'varargs' , 'varkw' , 'defaults' , 'kwonlyargs' ,
@@ -214,6 +215,8 @@ def decorate(func, caller, extras=(), kwsyntax=False):
214
215
does. By default kwsyntax is False and the the arguments are untouched.
215
216
"""
216
217
sig = inspect .signature (func )
218
+ if isinstance (func , functools .partial ):
219
+ func = functools .update_wrapper (func , func .func )
217
220
if iscoroutinefunction (caller ):
218
221
async def fun (* args , ** kw ):
219
222
if not kwsyntax :
@@ -230,6 +233,7 @@ def fun(*args, **kw):
230
233
if not kwsyntax :
231
234
args , kw = fix (args , kw , sig )
232
235
return caller (func , * (extras + args ), ** kw )
236
+
233
237
fun .__name__ = func .__name__
234
238
fun .__doc__ = func .__doc__
235
239
fun .__wrapped__ = func
0 commit comments