title: Monkey patching with a partial function
body: <p>I'm trying to monkeypatch a method on <code>SomeClass</code> from an imported package:</p>
  
  <pre><code>from somepackage import SomeClass
  
  def newmethod(obj, node, **kwargs):
      """ """
  
  SomeClass.oldmethod = newmethod
  </code></pre>
  
  <p>Where <code>obj</code> and <code>node</code> are in the default call signature of <code>SomeClass.oldmethod</code>:</p>
  
  <pre><code>class SomeClass(object):
  
      def oldmethod(obj, node):
          """ """  
  </code></pre>
  
  <p>I'm aware that monkeypatching is not good practice, but we need a workaround while we fix some issues that otherwise can't be tackled.  The above approach works FINE, but we'd like to use partial functions to do this.  For example:</p>
  
  <pre><code>from functools import partial
  newmethod_a = partial(newmethod, foo='a')
  newmethod_b = partial(newmethod, foo='b')
  </code></pre>
  
  <p>The partial function is being called because we need to pass different **kwargs.  But when I try to overload now:</p>
  
  <pre><code>SomeClass.oldmethod = newmethod_a
  </code></pre>
  
  <p>I get an error related to the number of arguments passed, but it's very specific to my problem so pasting it might not be helpful...  The error I think is related to the call signature of <code>oldmethod</code> taking two positional arguments (<code>obj, node</code>), and my partial functions aren't passing a reference to the <code>obj</code> and <code>node</code> correctly.  I've tried different constructions like:</p>
  
  <pre><code>newmethod_a = partial(SomeClass.newmethod, foo='a')
  </code></pre>
  
  <p>I'm sorry that I can't produce a minimal working example.  I hoped maybe an expert would just recognize this issue from experience and tell me if what I'm attempting is even possible within the scope of <code>partial</code>.</p>
  
  <p>Thanks</p>