Skip to content

Commit bf2e0ac

Browse files
Add support for decoration of constructors
Resolves #9
1 parent 58af367 commit bf2e0ac

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

fastargs/decorators.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,39 @@ def __call__(self, *args, **kwargs):
4040
else:
4141
raise e
4242

43-
43+
def extract_function(func):
44+
if hasattr(func, '__fastarg_wrapper'):
45+
return getattr(func, '__fastarg_wrapper')
46+
else:
47+
return WrappedFunction(func)
4448

4549
def param(parameter, alias=None):
4650
if isinstance(parameter, str):
4751
parameter = tuple(parameter.split('.'))
4852

49-
if alias==None:
53+
if alias is None:
5054
alias = parameter[-1]
5155

5256
def wrapper(func):
53-
if not isinstance(func, WrappedFunction):
54-
func = WrappedFunction(func)
57+
58+
func = extract_function(func)
59+
5560
func.add_arg(parameter, alias)
56-
return func
61+
62+
def result(*args, **kwargs):
63+
return func(*args, **kwargs)
64+
65+
setattr(result, '__fastarg_wrapper', func)
66+
return result
67+
5768
return wrapper
5869

5970
def section(section):
6071
if isinstance(section, str):
6172
section = tuple(section.split('.'))
6273

6374
def wrapper(func):
64-
if not isinstance(func, WrappedFunction):
65-
func = WrappedFunction(func)
75+
func = extract_function(func)
6676
func.set_section(section)
6777
return func
6878
return wrapper

0 commit comments

Comments
 (0)