Skip to content

Commit 0739716

Browse files
committed
misc: Make _memoized_instances idempotent
1 parent 2080ba3 commit 0739716

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

devito/tools/memoization.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def _memoized_instances(cls: type[InstanceType]) -> type[InstanceType]:
146146
only happens once for a cached instance.
147147
"""
148148

149+
# If the decorator has already been applied (e.g. to a parent class), don't reapply
150+
if getattr(cls, '__has_memoized_instances', False):
151+
return cls
152+
cls.__has_memoized_instances = True
153+
149154
cache: WeakValueCache[int, InstanceType] = WeakValueCache()
150155
new = cls.__new__
151156
init = cls.__init__

0 commit comments

Comments
 (0)