You generally can't reference a class by its name in its own definition because it hasn't been created yet. One way to (sometimes) workaround that limitation is by using what is know as a class decorator (see PEP 3129), which is a function that modifies a class after it's created.
Here's a good tutorial I found about them and how they work.
Since we want to pass arguments to the decorator, there's a need for an additional function that will act as what you could call a "decorator factory" that generates the needed class decorator on-the-fly based on the arguments passed to it.
Here's what I mean:
def decorate(func, arg):
def decorator(cls):
setattr(cls, 'foo', arg)
setattr(cls, 'bar', func(arg))
return cls
return decorator
f = lambda s: s[::-1]
@decorate(f, 'foo')
class A:
pass
print(A.foo) # -> foo
print(A.bar) # -> oof
Here's another way that also uses Python's decorator syntax, but in a slightly unconventional way in the sense that it's being used to modify a class attribute that would normally have become a method in such a way that it's value will instead be the result of calling some specified function with the argument given:
def call(*argv, **kwargs):
def call_fn(fn):
return fn(*argv, **kwargs)
return call_fn
f = lambda s: s[::-1]
class A:
foo = 'foo'
@call(f, foo) # Makes bar become the result of calling f with the argument.
def bar(func, arg):
return func(arg)
print(A.foo) # -> foo
print(A.bar) # -> oof