class Foo:

    def __init__(self, x):
        self.x = x

def bar(self):
    print('bar:', self.x)
bar.__name__ = 'foobar'
Foo.foobar = bar
f = Foo(12)
f.foobar()
f.foobar.__name__
How to add method using metaclass