Skip to content

Commit

Permalink
Add support for decoration of constructors
Browse files Browse the repository at this point in the history
Resolves #9
  • Loading branch information
GuillaumeLeclerc committed May 14, 2021
1 parent 58af367 commit bf2e0ac
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions fastargs/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,39 @@ def __call__(self, *args, **kwargs):
else:
raise e


def extract_function(func):
if hasattr(func, '__fastarg_wrapper'):
return getattr(func, '__fastarg_wrapper')
else:
return WrappedFunction(func)

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

if alias==None:
if alias is None:
alias = parameter[-1]

def wrapper(func):
if not isinstance(func, WrappedFunction):
func = WrappedFunction(func)

func = extract_function(func)

func.add_arg(parameter, alias)
return func

def result(*args, **kwargs):
return func(*args, **kwargs)

setattr(result, '__fastarg_wrapper', func)
return result

return wrapper

def section(section):
if isinstance(section, str):
section = tuple(section.split('.'))

def wrapper(func):
if not isinstance(func, WrappedFunction):
func = WrappedFunction(func)
func = extract_function(func)
func.set_section(section)
return func
return wrapper

0 comments on commit bf2e0ac

Please sign in to comment.