A decorator for producing robust fluent API interfaces by returning a copy of self
1 2 3 4 5 6 7 8 9 10 11 | from functools import wraps
from copy import deepcopy
def fluent(method):
"""Used to define fluent API class methods"""
@wraps(method)
def wrapped(self, *args, **kwargs):
dupe = deepcopy(self)
method(dupe, *args, **kwargs)
return dupe
return wrapped
|