I am trying to make a python decorator that adds attributes to methods of a class so that I can access and modify those attributes from within the method itself. The decorator code is 

```
from types import MethodType
class attribute(object):

    def __init__(self, **attributes):
        self.attributes = attributes

    def __call__(self, function):

        class override(object):

            def __init__(self, function, attributes):
                self.__function = function
                for att in attributes:
                    setattr(self, att, attributes[att])

            def __call__(self, *args, **kwargs):
                return self.__function(*args, **kwargs)

            def __get__(self, instance, owner):
                return MethodType(self, instance, owner) 

        retval = override(function, self.attributes)
        return retval

```

I tried this decorator on the toy example that follows.

```
    class bar(object):

        @attribute(a=2)
        def foo(self):
            print self.foo.a
            self.foo.a = 1

```

Though I am able to access the value of attribute 'a' from within foo(), I can't set it to another value. **Indeed, when I call `bar().foo()`, I get the following AttributeError.** 

```
AttributeError: 'instancemethod' object has no attribute 'a'

```

Why is this? More importantly how can I achieve my goal?

---

**Edit**

Just to be more specific, I am trying to find a simple way to implement static variable that are located within class methods. Continuing from the example above, I would like instantiate `b = bar()`, call both `foo()` and `doo()` methods and then access `b.foo.a` and `b.doo.a` later on.

```
    class bar(object):

        @attribute(a=2)
        def foo(self):
            self.foo.a = 1

        @attribute(a=4)
        def doo(self):
            self.foo.a = 3

```