How to make python function always unbound even assigned to a class attribute
Question: Having the following code, what can I do with the 'foo' function to make it
unbound in any case even if it is assigned to class attribute? Overriding
__get__ doesn't help - as far as I understand because it is not used when
function is absent from __dict__ of an instance (it is so in case of class
attributes). But what else can be done here?

    
    
    def foo(x):
        print(x)
    
    def foo_get(self, obj, type=None):
        return foo
    
    foo.__get__ = foo_get
    
    class A(object):
        def __init__(self):
            self.f = foo
    class B(object):
        f = foo
    
    
    a = A()
    
    print(a.f)               #<function foo at 0x2321d10>
    print(a.f.__get__(a, A)) #<function foo at 0x2321d10>
    
    b = B()
    
    print(b.f)               #<bound method B.foo of <__main__.B object at 0x23224d0>>
    


Answer: I'm pretty sure you want
[@staticmethod](http://docs.python.org/library/functions.html#staticmethod).

`foo = staticmethod(foo)`

You can also define `__get__` on a callable class:

    
    
    class Foo(object):
        def __get__(self, obj, type=None):
            return self
    
        def __call__(self, x):
            print(x)
    
    foo = Foo()
    
    class A(object):
        def __init__(self):
            self.f = foo
    class B(object):
        f = foo
    
    
    foo(1) # 1
    a = A()
    
    a.f(1) # 1
    print(a.f)               #<function foo at 0x2321d10>
    print(a.f.__get__(a, A)) #<function foo at 0x2321d10>
    
    b = B()
    b.f(1) # 1
    
    
    print(b.f)               #<__main__.Foo object at 0x7fa8c260be10>
    

It's one extra level of indentation and a few extra lines of code, but that's
how it can be done, if it's important.

