Decorators on bound methods with access to class and his ancestors
<p>When I decorated the bound method in Python class, I need get some info in this decorator from outer class. Is that possible?</p>

<p>For example:</p>

<pre><code>def modifier(func):
    import sys
    cls_namespace = sys._getframe(1).f_locals
    cls_namespace['data']  # dictonary has no key 'data'
    ...
    return func

class Parent:
    data = "Hi!"

class Child(Parent):

    @modifier
    def method(self):
        pass
</code></pre>

<p>the <code>cls_namespace</code> is just incomplete namespace of current class without <code>data</code> field that I need to get.</p>

<p>Is there ways to get it in decorator?</p>

<p>Not that the very first arg passed to your decorator's wrapper will be an objects instance (<code>self</code>). Thanks to it you can access w=everything you need. </p>

<p>See Raphaels response: 
<a href="http://stackoverflow.com/questions/11731136/python-class-method-decorator-w-self-arguments">Related issue</a></p>

<pre><code>def wrapped(self, *f_args, **f_kwargs):
</code></pre>

<p>self is the very first argument</p>

python class reflection decorator python-decorators