games/util.py
2023-06-07 22:23:34 -07:00

16 lines
413 B
Python

import typing as tp
CALL_COUNTS = {}
T = tp.TypeVar("T")
P = tp.ParamSpec("P")
def count_calls(f: tp.Callable[P, T]) -> tp.Callable[P, T]:
# TODO: this isn't giving accurate results with the play_human?
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
cc = CALL_COUNTS.setdefault(f.__name__, 0)
CALL_COUNTS[f.__name__] = cc + 1
return f(*args, **kwargs)
return wrapper