I often use the following idiom for static initialization:
def compute_answer() -> int: if compute_answer.ret is None: # Do stuff that only happens