This repository was archived by the owner on Feb 2, 2026. It is now read-only.
This repository was archived by the owner on Feb 2, 2026. It is now read-only.
Description
Currently a lot of functions are almost identical, because they mainly consist of cache handling code. Using decorators most of this code duplication could be avoided. I implemented a demonstration for this.
This very long code
def _get_trigger_delay(self):
if not self._driver_operation_simulate and not self._get_cache_valid():
value = float(self._ask("trigger:delay?"))
self._trigger_delay = value
self._set_cache_valid()
return self._trigger_delay
def _set_trigger_delay(self, value):
value = float(value)
if not self._driver_operation_simulate:
self._write('trigger:delay %g' % value)
self._trigger_delay = value
self._set_cache_valid()
becomes
@cacheable
def _get_trigger_delay(self):
return value = float(self._ask("trigger:delay?"))
@cacheable
def _set_trigger_delay(self, value):
self._write('trigger:delay %g' % value)
Which is much easier to read an less error-prone. At the moment this is just a demonstration, but if there is interest I can implement a real solution which is compatible with the current caching mechanism.
Code: https://gist.github.com/herm/9e9d02218f5a1dddd8d9
Reactions are currently unavailable
Currently a lot of functions are almost identical, because they mainly consist of cache handling code. Using decorators most of this code duplication could be avoided. I implemented a demonstration for this.
This very long code
def _get_trigger_delay(self): if not self._driver_operation_simulate and not self._get_cache_valid(): value = float(self._ask("trigger:delay?")) self._trigger_delay = value self._set_cache_valid() return self._trigger_delay def _set_trigger_delay(self, value): value = float(value) if not self._driver_operation_simulate: self._write('trigger:delay %g' % value) self._trigger_delay = value self._set_cache_valid()becomes
@cacheable def _get_trigger_delay(self): return value = float(self._ask("trigger:delay?")) @cacheable def _set_trigger_delay(self, value): self._write('trigger:delay %g' % value)Which is much easier to read an less error-prone. At the moment this is just a demonstration, but if there is interest I can implement a real solution which is compatible with the current caching mechanism.
Code: https://gist.github.com/herm/9e9d02218f5a1dddd8d9