diff --git a/GaudiConfiguration/python/GaudiConfig2/semantics.py b/GaudiConfiguration/python/GaudiConfig2/semantics.py index 137feab28f2c2f5631341bc9d78d65824317d8cc..576851d7da02e8c9f569c5f43be8ecaec896d625 100644 --- a/GaudiConfiguration/python/GaudiConfig2/semantics.py +++ b/GaudiConfiguration/python/GaudiConfig2/semantics.py @@ -28,9 +28,17 @@ class PropertySemantics(object): __handled_types__ = () def __init__(self, cpp_type, name=None): - self.name = None + self._name = name self.cpp_type = cpp_type + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + @property def cpp_type(self): return self._cpp_type @@ -341,6 +349,16 @@ class SequenceSemantics(PropertySemantics): self.value_semantics = valueSem or getSemanticsFor( list(extract_template_args(cpp_type))[0] ) + self.value_semantics.name = name + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + self.value_semantics.name = "{} element".format(self._name) def store(self, value): new_value = _ListHelper(self.value_semantics) @@ -464,7 +482,19 @@ class MappingSemantics(PropertySemantics): super(MappingSemantics, self).__init__(cpp_type, name) template_args = list(extract_template_args(cpp_type)) self.key_semantics = getSemanticsFor(template_args[0]) + self.key_semantics.name = "{} key".format(name) self.value_semantics = getSemanticsFor(template_args[1]) + self.value_semantics.name = "{} value".format(name) + + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + self.key_semantics.name = "{} key".format(self._name) + self.value_semantics.name = "{} value".format(self._name) def store(self, value): new_value = _DictHelper(self.key_semantics, self.value_semantics) diff --git a/GaudiConfiguration/tests/python/test_error_conditions.py b/GaudiConfiguration/tests/python/test_error_conditions.py index 123c069224f066f97dafd23cbc98ac9aaa21e31c..3e187023d340415db52e2bd7dc041a72139eb38e 100644 --- a/GaudiConfiguration/tests/python/test_error_conditions.py +++ b/GaudiConfiguration/tests/python/test_error_conditions.py @@ -12,8 +12,17 @@ import pytest def test_1(): - from GaudiConfig2.Configurables.TestConf import AlgWithVectors + from GaudiConfig2.Configurables.TestConf import AlgWithMaps, AlgWithVectors alg = AlgWithVectors() with pytest.raises(TypeError, match=r"cannot set property VS .*"): alg.VS = [3] + + alg = AlgWithMaps() + with pytest.raises(TypeError, match=r"cannot set property MSS key .*"): + alg.MSS[3] = "value" + with pytest.raises(TypeError, match=r"cannot set property MSS value .*"): + alg.MSS["key"] = 3 + alg.MIV[3] = [] + with pytest.raises(TypeError, match=r"cannot set property MIV value element.*"): + alg.MIV[3].append(5)