hephy-dd / comet

COMET - Control and Measurement Toolkit
GNU General Public License v3.0
2 stars 2 forks source link

Issue with drivers as class attributes #27

Closed arnobaer closed 4 years ago

arnobaer commented 4 years ago

It turned out to be quite tedious/impractical to forward attributes using property classes, implementing Driver sub modules. Possible solution: stick back to classic attribute instances, prevent attribute assignments for Driver instances.

class Axis(Driver):
    def __init__(self, resource, index):
        super().__init__(resource)
        self._index = index

class Venus1(Driver):
    def __init__(self, resource):
        super().__init__(resource)
        self.x = Axis(resource, 1)
        self.y = Axis(resource, 2)
        self.z = Axis(resource, 3)

# Prevent accidental assignments
>>> device = Venus1(...)
>>> device.x = 4
...
AttributeError: can't set attribute