Preserving argument default values while method chaining
<p>If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee() without having to change the client code. E.g., if wrapee() is defined as:</p>

<pre><code>def wrapee(param1, param2="Some Value"):
  # Do something
</code></pre>

<p>Then, one way to define wrapper() is:</p>

<pre><code>def wrapper(param1, param2="Some Value"):
  # Do something
  wrapee(param1, param2)
  # Do something else.
</code></pre>

<p>However, wrapper() has to make assumptions on the default value for param2 which I don't like. If I have the control on wrapee(), I would define it like this:</p>

<pre><code>def wrapee(param1, param2=None):
  param2 = param2 or "Some Value"
  # Do something
</code></pre>

<p>Then, wrapper() would change to:</p>

<pre><code>def wrapper(param1, param2=None):
  # Do something
  wrapee(param1, param2)
  # Do something else.
</code></pre>

<p>If I don't have control on how wrapee() is defined, how best to define wrapper()? One option that comes into mind is to use to create a dict with non-None arguments and pass it as dictionary arguments, but it seems unnecessarily tedious.</p>

<p>Update:</p>

<p>The solution is to use both the list and dictionary arguments like this:</p>

<pre><code>def wrapper(param1, *args, **argv):
  # Do something
  wrapee(param1, *args, **argv)
  # Do something else.
</code></pre>

<p>All the following calls are then valid:</p>

<pre><code>wrapper('test1')
wrapper('test1', 'test2')
wrapper('test1', param2='test2')
wrapper(param2='test2', param1='test1')
</code></pre>
