From 513e88446b39ce7ee0d0a38ebe252fed9dab68c8 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 24 Dec 2024 11:35:04 +0700 Subject: [PATCH] add: expand iterators passed to constructors --- htmlgenerator/base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/htmlgenerator/base.py b/htmlgenerator/base.py index a39a033..159dd28 100644 --- a/htmlgenerator/base.py +++ b/htmlgenerator/base.py @@ -2,6 +2,7 @@ import copy import string +import types from typing import Any, Callable, Generator, Iterable, List, Optional, Tuple, Union from .lazy import Lazy, resolve_lazy @@ -57,7 +58,14 @@ def __init__(self, *children): Uses the given arguments to initialize the list which represents the child objects """ - super().__init__(children) + child_elements = [] + for c in children: + if isinstance(c, types.GeneratorType): + child_elements.extend(c) + else: + child_elements.append(c) + + super().__init__(child_elements) def render_children( self, context: dict, stringify: bool = True, fragment: Optional[str] = None