提交 962f2b31 authored 作者: Olivier Breuleux's avatar Olivier Breuleux

ComponentList is addable with tuples and lists

上级 c68b9e44
...@@ -412,7 +412,15 @@ class ComponentList(Composite): ...@@ -412,7 +412,15 @@ class ComponentList(Composite):
c = Member(c) c = Member(c)
elif not isinstance(c, Component): elif not isinstance(c, Component):
raise TypeError('ComponentList may only contain Components.', c, type(c)) raise TypeError('ComponentList may only contain Components.', c, type(c))
self._components.append(c) self._components.append(c)
def __add__(self, other):
if isinstance(other, (list, tuple)):
return ComponentList(self._components + list(other))
def __radd__(self, other):
if isinstance(other, (list, tuple)):
return ComponentList(list(other) + self._components)
def __str__(self): def __str__(self):
return str(self._components) return str(self._components)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论