Partially Evaluating Python Classmethod Based on Where It's Accessed From
<p>I have what is essentially the following in python:</p>

<pre><code>class X(object): pass

class Y(object):
  @classmethod
  def method(cls, x_inst, *args, **kwargs):
    #do some work here that requires an instance of x
    pass
</code></pre>

<p>What I would like to do is add a dynamic property to all instances of <code>X</code> allowing acces to <code>Y</code> that implicitly fills in the first parameter of the <code>method</code> with the given instance. E.G I would like the following code to work identically:</p>

<pre><code># current
x = X()
result = Y.method(x, 1, 2, 3)

# desired
x = X()
x.Y.method(1, 2, 3)
</code></pre>

<p>There are several methods on several subclasses that I would like to implement this behaviour for. What I have done currently is to create a <code>YProxy</code> class that <code>X</code> actually returns, and then put split some of the code into that. It seems rather inelegant and hard to maintain however:</p>

<pre><code>class X(object):
  @property
  def Y(self):
    return YProxy(self)

class Y(object):
  @classmethod
  def method(cls, x_inst, *args, **kwargs):
    #do some work here that requires an instance of x
    pass

class YProxy(object):
  def __init__(self, x_inst):
    self.x_inst = x_inst

  def method(self, *args, **kwargs):
    return Y.method(self.x_inst, *args, **kwargs)
</code></pre>

<p>Is there any way to <em>conditionally</em> partially evaluate the classmethods on an object?</p>
