""" Contains utilities for working with classes. """ from collections import defaultdict class AccessTracker: """Proxy object to track attribute 'get' access on a target object.""" def __init__(self, target: object): """Initialize the tracker with a target object.""" self._target = target self._access_counts = defaultdict(int) def __getattr__(self, name: str): """Track attribute access and return the attribute.""" self._access_counts[name] += 1 return getattr(self._target, name) @property def target(self) -> object: """Return the target object, e.g. for accessing attributes without tracking.""" return self._target @property def attrs_accessed(self) -> dict: """Return a dictionary of accessed attribute names and their access counts.""" return self._access_counts