Skip to content

Commit b910b1c

Browse files
author
Sylvain MARIE
committed
Fixed TypeError when a func attribute is present on the function provided to create_function. Fixed #76
1 parent 9a0fdf0 commit b910b1c

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/makefun/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def create_function(func_signature, # type: Union[str, Signature]
268268
# update the signature
269269
_update_fields(f, name=func_name, qualname=qualname, doc=doc, annotations=annotations,
270270
defaults=tuple(defaults), kwonlydefaults=kwonlydefaults,
271-
module=module_name, **attrs)
271+
module=module_name, kw=attrs)
272272

273273
return f
274274

@@ -631,18 +631,22 @@ def _make(funcname, params_names, body, evaldict=None):
631631

632632

633633
def _update_fields(
634-
func, name, qualname=None, doc=None, annotations=None, defaults=(), kwonlydefaults=None, module=None, **kw
634+
func, name, qualname=None, doc=None, annotations=None, defaults=(), kwonlydefaults=None, module=None, kw=None
635635
):
636636
"""
637637
Update the signature of func with the provided information
638638
639639
This method merely exists to remind which field have to be filled.
640640
641-
:param self:
642641
:param func:
642+
:param name:
643+
:param qualname:
643644
:param kw:
644645
:return:
645646
"""
647+
if kw is None:
648+
kw = dict()
649+
646650
func.__name__ = name
647651

648652
if qualname is not None:

tests/test_issues.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
except ImportError:
88
from funcsigs import signature, Signature, Parameter
99

10-
from makefun import wraps, with_signature, partial
10+
from makefun import wraps, with_signature, partial, create_function
1111

1212

1313
@pytest.mark.skip("known to fail")
@@ -216,3 +216,11 @@ def bar(*args, **kwargs):
216216
pass
217217

218218
bar(1)
219+
220+
221+
def test_issue_76():
222+
def f(a):
223+
return a + 1
224+
225+
f2 = create_function("zoo(a)", f, func=f)
226+
assert f2(3) == 4

0 commit comments

Comments
 (0)