Unfortunately, in Python, a class attribute cannot refer to its class name. The following calls the nameerror:
class Foo(object): bar = Foo
In a situation where a class attribute must refer to its class name (in my case, its part of the validation scheme for the library), what is the clearest way to do this?
My next attempt:
class Foo(object): bar = None Foo.bar = Foo
This works, but it can be confusing even with comments, since you expect the class attribute to be initialized when the declaration is made, and not after the class is declared.
Does anyone have a better workaround?
source share