python-synthetica 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ from functools import wraps
2
+
3
+
4
+ def callback(cache_name):
5
+ def decorator(setter_func):
6
+ @wraps(setter_func)
7
+ def wrapper(self, new_value, *args, **kwargs):
8
+ # Get the current value of the property
9
+ prop_name = setter_func.__name__
10
+ current_value = getattr(self, f"_{prop_name}")
11
+
12
+ # Call the original setter function
13
+ result = setter_func(self, new_value, *args, **kwargs)
14
+
15
+ # If the value has changed, invalidate the cache
16
+ if current_value != new_value:
17
+ self.__dict__.pop(cache_name, None)
18
+
19
+ return result
20
+
21
+ return wrapper
22
+
23
+ return decorator