Added high level API for dynamic attributes
Closes #305 (closed)
add_attribute function for BaseDevice server was re-written to add high level API for read|write methods. The reading|writing is done through two new methods __dynamic_attribute_reader and __dynamic_attribute_writer, which become original read|write methods as arguments with help of functools.partial method
However, I had to make two ugly patches to provide backward compatibility with already existing servers:
-
our method to check whether read function is high-level is based on amount of input arguments. This fails with non-device patched methods (see #465 (closed) and !477 (merged)): such methods have 1 input argument, due to they are outside any class. I added try clause with check to the TypeError, containing "missing 1 required positional argument". However, this error could be potentially caused by user code
-
with write method there is no reliable way to detect whether this is high or low level API, so we try first high level API, and catch AttributeError with "has no attribute 'get_write_value'". If so, trying low level API. But again, could be caused by user code
I think we should add deprecated warning about low-level API in high-level servers and at some point turn this feature off - to avoid potential source of errors