I often use the following idiom for static initialization:
def compute_answer() -> int:
if compute_answer.ret is None:
# Do stuff that only happens the first time
compute_answer.ret = 42
return compute_answer.ret
compute_answer.ret = None
However, type checking with mypy gives the following errors:
compute.py:2: error: "Callable[[], int]" has no attribute "ret"
compute.py:4: error: "Callable[[], int]" has no attribute "ret"
compute.py:5: error: "Callable[[], int]" has no attribute "ret"
compute.py:7: error: "Callable[[], int]" has no attribute "ret"
How can I suppress these errors, especially locally (e.g., just this function/attribute)?