stop "conf"s all being the same dict#212
Conversation
|
The proposed fix changes the default from an empty dict to a None. This also changes the function signature so the type annotation needs to be fixed accordingly, i.e., from However, I don't think this is the right fix. The default really is an empty dict, and the use of None here is a workaround. The root problem is that in Suppose that instead of wanting the default empty dict, we do have two devices with the same list of arguments, so we do: Because this does not trigger I believe the right fix is to have make a copy of the |
|
@carandraug presumably any original dict is thrown away after device is created anyway, so I've made a different fix at #217 (unfortunately untested for now) |
…#211) This commit has serve_devices make a deepcopy of the devices argument so that in case we need to make changes to it, we don't modify the stuff in the caller. This commit reverts ef280c3 which was another fix for this issue. The way we support floating devices requires that we inject the index value on the device configuration. However, we don't want that to propagate to the caller which may be reusing that configuration (and it kinda does it when device configuration is not specified see discussion on #212).
…python-microscope#211) This commit has serve_devices make a deepcopy of the devices argument so that in case we need to make changes to it, we don't modify the stuff in the caller. This commit reverts ef280c3 which was another fix for this issue. The way we support floating devices requires that we inject the index value on the device configuration. However, we don't want that to propagate to the caller which may be reusing that configuration (and it kinda does it when device configuration is not specified see discussion on python-microscope#212).
Using a mutable object such as {} as default can lead to surprises
behaviour (see pylint notes for dangerous-default-value / W0102 at
https://pylint.pycqa.org/en/stable/user_guide/messages/warning/dangerous-default-value.html ).
Indeed, this triggered the issues #211, #212, and #274. So just make
the default None and convert to an empty dict.
When multiple devices are being created without a conf set, all
dev["conf"]s are pointing to the same dictionary, meaning that they all have the same_index. This was making it impossible to load both AndorAtmcd cameras being loaded at once on the cryoSIM at B24, Diamond Light Source as it hit this within the classAndorAtmcd: