If I need to wrap an existing method, say wrapee () from a new method, say wrapper (), and wrapee () provides default values for some arguments, how do I preserve my semantics without introducing unnecessary dependencies and maintenance? Let's say the goal is to be able to use wrapper () instead of wrapee () without changing the client code. For example, if wrapee () is defined as:
def wrapee(param1, param2="Some Value"):
Then one of the ways to determine the shell () is:
def wrapper(param1, param2="Some Value"):
wrapee(param1, param2)
However, wrapper () should make assumptions about the default value for param2, which I don't like. If I have control over wrapee (), I would define it like this:
def wrapee(param1, param2=None):
param2 = param2 or "Some Value"
Then wrapper () will change to:
def wrapper(param1, param2=None):
wrapee(param1, param2)
, wrapee(), wrapper()? , , , dict , None, , .
Update:
, , :
def wrapper(param1, *args, **argv):
wrapee(param1, *args, **argv)
:
wrapper('test1')
wrapper('test1', 'test2')
wrapper('test1', param2='test2')
wrapper(param2='test2', param1='test1')