Skip to content

Restore dynamic attribute functionality with unbound methods

Closes #454 (closed)

After MG #401 there were several complaints from users, who prefer to use unbound fset, fget, fisallowed methods for dynamic attribute. Unfortunately, this led to the error, due to during dynamic attribute initialization we wrap bounded methods with async executor, and this changes method signature. But unbounded methods are left intact, and when later one of these methods is called, async executor is "confused" with the old, untouched signature of the unbound method.

First, @ajoubertza updated and substantially improved the documentation about dynamic attributes, which was outdated.

Second, the code was modified in a way, that if the server is run in async mode and unbound function was passes as argument, it will be automatically substituted with the bound method. In case the bound method cannot be found - ValueError will be generated.

We also modified the logic of dyn_attr method of DeviceClass, and now it throws an error when attributes cannot be added. This means a device server will fail to start if there is an exception while creating dynamic attributes. Previously, the device would have continued startup regardless of this kind of error.

Additionally, we fixed a rare issue with double method wrapping, if it was use twice in add_attribute function.

Finally, new tests with unbound read/write functions for dynamic attribute were added, as well as test for the non device methods for attributes, attribute access with default names, old sardana dynamic attribute API and double wrapping. Now, we hope, tests covers all possible cases.

Edited by Anton Joubert

Merge request reports