I'm writing a class, which has some class variables, which are required for a class method, so it's not an option to make them instance variables. Some of those class variables are dictionaries, with (partially) the same keys, which could be easily defined by writing the first dict manually and then using dict comprehensions to create the other ones.
My idea was something like
class MyClass:
A: dict = { some manually written items }
B: dict = { k: *stuff containing A[k]* for k in { *subset of keys from A* } }
*some more dicts like this*
My hope was, that when the interpreter is reading the class body from top to bottom, A
would be in scope while interpreting the expression for B
but that proved to be wrong and the class object also cannot be accessed, while the interpretation of the same class isn't completed yet.
Does python have a way to solve this, like, let's say, a method similar to __init__
but that isn't called after the instantiation of the class but right after the interpretation?