From 0909f92e121f2181ef52e0724c76b7e207833c92 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Mon, 17 Jan 2022 10:44:41 +0100 Subject: [PATCH] UniqueObject create a class to be used for unique objects. better for debugging and documentation than just using object() + remove unused unique objects Change-Id: I32f65960ea2fbee4fccbeb49a4e11176b7185aa0 Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/27455 Tested-by: Jenkins Automated Tests Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker --- doc/source/reference.rst | 2 ++ secop/lib/__init__.py | 11 ++++++++--- secop/modules.py | 7 +++++-- secop/params.py | 2 -- secop/properties.py | 6 +++--- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/doc/source/reference.rst b/doc/source/reference.rst index d85b838..0f4fc94 100644 --- a/doc/source/reference.rst +++ b/doc/source/reference.rst @@ -4,6 +4,8 @@ Reference Module Base Classes ................... +.. autodata:: secop.modules.Done + .. autoclass:: secop.modules.Module :members: earlyInit, initModule, startModule, pollerClass diff --git a/secop/lib/__init__.py b/secop/lib/__init__.py index c0c21c7..e942ff5 100644 --- a/secop/lib/__init__.py +++ b/secop/lib/__init__.py @@ -31,9 +31,6 @@ from configparser import ConfigParser from os import environ, path -unset_value = object() - - class GeneralConfig: def __init__(self): self._config = None @@ -319,3 +316,11 @@ def formatStatusBits(sword, labels, start=0): if sword & (1 << i) and lbl: result.append(lbl) return result + + +class UniqueObject: + def __init__(self, name): + self.name = name + + def __repr__(self): + return 'UniqueObject(%r)' % self.name diff --git a/secop/modules.py b/secop/modules.py index 1cdca29..4793450 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -31,14 +31,17 @@ from secop.datatypes import ArrayOf, BoolType, EnumType, FloatRange, \ IntRange, StatusType, StringType, TextType, TupleOf from secop.errors import BadValueError, ConfigError, \ ProgrammingError, SECoPError, SilentError, secop_error -from secop.lib import formatException, mkthread +from secop.lib import formatException, mkthread, UniqueObject from secop.lib.enum import Enum from secop.params import Accessible, Command, Parameter from secop.poller import BasicPoller, Poller from secop.properties import HasProperties, Property from secop.logging import RemoteLogHandler, HasComlog -Done = object() #: a special return value for a read/write function indicating that the setter is triggered already +Done = UniqueObject('already set') +"""a special return value for a read/write function + +indicating that the setter is triggered already""" class HasAccessibles(HasProperties): diff --git a/secop/params.py b/secop/params.py index 9add5a8..f7c287c 100644 --- a/secop/params.py +++ b/secop/params.py @@ -31,8 +31,6 @@ from secop.datatypes import BoolType, CommandType, DataType, \ from secop.errors import BadValueError, ProgrammingError from secop.properties import HasProperties, Property -UNSET = object() # an argument not given, not even None - class Accessible(HasProperties): """base class for Parameter and Command diff --git a/secop/properties.py b/secop/properties.py index 047c147..74ba68a 100644 --- a/secop/properties.py +++ b/secop/properties.py @@ -26,8 +26,11 @@ import inspect from secop.errors import BadValueError, ConfigError, ProgrammingError +from secop.lib import UniqueObject from secop.lib.py35compat import Object +UNSET = UniqueObject('undefined value') #: an unset value, not even None + class HasDescriptors(Object): @classmethod @@ -39,9 +42,6 @@ class HasDescriptors(Object): raise ProgrammingError('misplaced trailing comma after %s.%s' % (cls.__name__, '/'.join(bad))) -UNSET = object() # an unset value, not even None - - # storage for 'properties of a property' class Property: """base class holding info about a property