Skip to content

Commit

Permalink
correct caching problem of not handle mutable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
m-rauen committed Dec 3, 2024
1 parent ca303e2 commit 6696fc2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions overreact/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6696fc2

Please sign in to comment.