Skip to content

Commit 0843d2c

Browse files
Fix clonefunc for annotations and kwdefaults. (#594)
1 parent 5f9161d commit 0843d2c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

blacksheep/utils/meta.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def import_child_modules(root_path: Path):
3333

3434
def clonefunc(func):
3535
"""
36-
Clone a function, preserving its name and docstring.
36+
Clone a function, preserving its name, docstring, annotations and kwdefaults.
3737
"""
3838
new_func = func.__class__(
3939
func.__code__,
@@ -44,6 +44,9 @@ def clonefunc(func):
4444
)
4545
new_func.__doc__ = func.__doc__
4646
new_func.__dict__ = copy.deepcopy(func.__dict__)
47+
new_func.__annotations__ = copy.deepcopy(func.__annotations__)
48+
if func.__kwdefaults__:
49+
new_func.__kwdefaults__ = copy.deepcopy(func.__kwdefaults__)
4750
return new_func
4851

4952

0 commit comments

Comments
 (0)