diff --git a/overreact/coords.py b/overreact/coords.py index 840328d..cb54e84 100644 --- a/overreact/coords.py +++ b/overreact/coords.py @@ -2,7 +2,7 @@ # TODO(schneiderfelipe): add types to this module from __future__ import annotations -from functools import lru_cache +import functools __all__ = ["find_point_group", "symmetry_number"] @@ -1680,8 +1680,22 @@ def gyradius(atommasses, atomcoords, method="iupac"): else: msg = f"unavailable method: '{method}'" raise ValueError(msg) - -@lru_cache() + +def ignore_unhashable(func): + uncached = func.__wrapped__ + attributes = functools.WRAPPER_ASSIGNMENTS + ('cache_info', 'cache_clear') + @functools.wraps(func, assigned=attributes) + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except TypeError as error: + if 'unhashable type' in str(error): + return uncached(*args, **kwargs) + raise + wrapper.__uncached__ = uncached + return wrapper +@ignore_unhashable +@functools.lru_cache() def inertia(atommasses, atomcoords, align=True): r"""Calculate primary moments and axes from the inertia tensor.