Python: class static member pointing to itself?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6083708/can-i-get-a-reference-to-the-owner-class-during-the-init-method-of-a-descri">Can I get a reference to the &#39;owner&#39; class during the <strong>init</strong> method of a descriptor?</a>  </p>
</blockquote>



<p>Code is worth a thousand words:</p>

<pre><code>&gt;&gt;&gt; class ShortRib(object):
&gt;&gt;&gt;     def __init__(self, owner):
&gt;&gt;&gt;         self.owner = owner
&gt;&gt;&gt; 
&gt;&gt;&gt;     ... some more methods and stuff ...
&gt;&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; class Cow(object):
&gt;&gt;&gt;     shortRib = ShortRib(self)
&gt;&gt;&gt; 
&gt;&gt;&gt; 
&gt;&gt;&gt; class BrownCow(Cow):
&gt;&gt;&gt;     pass
&gt;&gt;&gt; 
&gt;&gt;&gt; BrownCow.shortRib.owner
&lt;class '__main__.BrownCow'&gt;
</code></pre>

<p>This doesn't work, though i wish it would. Basically, I want each class to have some static/class variables (i'm not sure which it is in this case?) but need each of those guys to know who (which class) it belongs to. Unfortunately, I can't "get" at the class in the body of the class declaration. Of course, I could always do this using a decorator:</p>

<pre><code>&gt;&gt;&gt; def vars(**kwargs):
&gt;&gt;&gt;     def wrap(cls):    
&gt;&gt;&gt;         for k, w in kwargs.items():
&gt;&gt;&gt;             setattr(cls, k, w(cls))
&gt;&gt;&gt;         return cls
&gt;&gt;&gt;     return wrap
&gt;&gt;&gt; 
&gt;&gt;&gt; @vars(shortRib=lambda cls: ShortRib(cls)
&gt;&gt;&gt; class BrownCow(Cow):
&gt;&gt;&gt;     ...
&gt;&gt;&gt;
&gt;&gt;&gt; BrownCow.shortRib.owner
</code></pre>

<p>which would work. Another way would to have a class decorator that goes through all the shortRibs and similar static variables and sets their owner after the class declaration is complete. However, this seems like an incredibly roundabout and unintuitive way of doing what should be a pretty simple operation: having the static/class members of a class know who they belong to.</p>

<p>Is there a "proper" way of doing this?</p>

<p><strong>Clarification:</strong></p>

<p>I want these members to belong to the class, not to the instances. I'm trying to go for a almost-purely-functional style, using classes only for inheritance of shared behavior, and not creating instances of them at all. Instances would tend to give my functions access to arbitrary instance data shared across all functions, which would break the pure-functioness I am trying for. I could just use empty instances which I don't touch, but I think using pure classes would be cleaner.</p>
