Skip to content

Commit 4ba6740

Browse files
committed
Add __add__ and __radd__ methods to TagList
1 parent a61037d commit 4ba6740

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

htmltools/_core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,28 @@ def insert(self, i: SupportsIndex, item: TagChild) -> None:
299299

300300
self[i:i] = _tagchilds_to_tagnodes([item])
301301

302+
def __add__(self, item: Iterable[TagChild]) -> TagList:
303+
"""
304+
Return a new TagList with the item added at the end.
305+
"""
306+
307+
should_not_expand = isinstance(item, str)
308+
if should_not_expand:
309+
return TagList(self, item)
310+
311+
return TagList(self, *item)
312+
313+
def __radd__(self, item: Iterable[TagChild]) -> TagList:
314+
"""
315+
Return a new TagList with the item added to the beginning.
316+
"""
317+
318+
should_not_expand = isinstance(item, str)
319+
if should_not_expand:
320+
return TagList(item, self)
321+
322+
return TagList(*item, self)
323+
302324
def tagify(self) -> "TagList":
303325
"""
304326
Convert any tagifiable children to Tag/TagList objects.

0 commit comments

Comments
 (0)