From 0836713c590b2f8947fa0ad28c2f6da3644f3196 Mon Sep 17 00:00:00 2001 From: Thomas Fish Date: Wed, 16 Jun 2021 17:47:28 +0100 Subject: [PATCH] deepcopy conf dict when device is created --- microscope/device_server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/microscope/device_server.py b/microscope/device_server.py index 01bd2f22..3444bf6c 100644 --- a/microscope/device_server.py +++ b/microscope/device_server.py @@ -43,6 +43,7 @@ import sys import time import typing +from copy import deepcopy from collections.abc import Iterable from dataclasses import dataclass from logging import StreamHandler @@ -81,7 +82,7 @@ def device( cls: typing.Callable, host: str, port: int, - conf: typing.Mapping[str, typing.Any] = None, + conf: typing.Mapping[str, typing.Any] = {}, uid: typing.Optional[str] = None, ): """Define devices and where to serve them. @@ -119,8 +120,6 @@ def construct_devices() -> typing.Dict[str, Device]: ] """ - if conf is None: - conf = {} if not callable(cls): raise TypeError("cls must be a callable") elif isinstance(cls, type): @@ -128,7 +127,7 @@ def construct_devices() -> typing.Dict[str, Device]: raise TypeError("uid must be specified for floating devices") elif not issubclass(cls, FloatingDeviceMixin) and uid is not None: raise TypeError("uid must not be given for non floating devices") - return dict(cls=cls, host=host, port=int(port), uid=uid, conf=conf) + return dict(cls=cls, host=host, port=int(port), uid=uid, conf=deepcopy(conf)) def _create_log_formatter(name: str):