Skip to content
Snippets Groups Projects
Commit 77a94cfa authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

GaudiConfig2: allow implicit conversion from tuple for ListHelper

To support `Gaudi::Property<DataOjbIDColl>` we need to allow implicit
conversion from `tuple`.
parent fa93df19
No related branches found
No related tags found
1 merge request!1518GaudiConfig2: strict type checking for list properties
......@@ -360,9 +360,11 @@ class SequenceSemantics(PropertySemantics):
self.value_semantics.name = "{} element".format(self._name)
def store(self, value):
if not isinstance(value, (list, _ListHelper)):
if not isinstance(value, (list, _ListHelper, tuple)):
raise TypeError(
"list expected, got {!r} in assignment to {}".format(value, self.name)
"list or tuple expected, got {!r} in assignment to {}".format(
value, self.name
)
)
new_value = _ListHelper(self.value_semantics)
new_value.extend(value)
......
......@@ -84,6 +84,15 @@ def test_opt_value():
assert s.opt_value(d) == ["a", "b", "c"]
def test_implicit_conversion():
s = S.getSemanticsFor("std::vector<std::string, alloc<string> >")
# For backwards-compatibility (i.e. for Property<DataObjIDColl>)
# we support assignment from tuple:
d = s.store(("a", "b", "c"))
assert d == list("abc")
def test_assignment_bad():
s = S.getSemanticsFor("std::vector<std::string, alloc<string> >")
with pytest.raises(TypeError):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment