diff --git a/pyhtml/__types.py b/pyhtml/__types.py
index 7c25cbd..db33a79 100644
--- a/pyhtml/__types.py
+++ b/pyhtml/__types.py
@@ -4,7 +4,7 @@
Type definitions
"""
from typing import Union, TYPE_CHECKING
-from collections.abc import Generator
+from collections.abc import Generator, Sequence
if TYPE_CHECKING:
@@ -33,7 +33,7 @@
ChildrenType = Union[
ChildElementType,
- list[ChildElementType],
+ Sequence[ChildElementType],
'Generator[ChildElementType, None, None]',
# TODO: Would an `Any` type for the generator return be better, even though
# it would be discarded?
diff --git a/pyhtml/__util.py b/pyhtml/__util.py
index b6c975d..0c8537c 100644
--- a/pyhtml/__util.py
+++ b/pyhtml/__util.py
@@ -4,7 +4,7 @@
Random helpful functions used elsewhere
"""
from typing import Any, TypeVar
-from collections.abc import Generator
+from collections.abc import Generator, Sequence
from .__types import ChildrenType, ChildElementType
@@ -143,6 +143,10 @@ def flatten_list(the_list: list[ChildrenType]) -> list[ChildElementType]:
result.extend(item)
elif isinstance(item, Generator):
result.extend(item)
+ elif isinstance(item, str):
+ result.append(item)
+ elif isinstance(item, Sequence):
+ result.extend(item)
else:
result.append(item)
return result
diff --git a/pyproject.toml b/pyproject.toml
index 44abb3a..ace61ad 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,22 +1,16 @@
[tool.poetry]
name = "pyhtml-enhanced"
-version = "2.0.1"
+version = "2.0.2"
description = "A library for building HTML documents with a simple and learnable syntax"
authors = ["Miguel Guthridge "]
license = "MIT"
readme = "README.md"
-packages = [{include = "pyhtml"}]
+packages = [{ include = "pyhtml" }]
repository = "https://github.com/COMP1010UNSW/pyhtml-enhanced"
documentation = "https://github.com/COMP1010UNSW/pyhtml-enhanced#README"
-keywords = [
- 'html',
- 'template',
- 'pyhtml',
- 'markup',
- 'documentation',
-]
+keywords = ['html', 'template', 'pyhtml', 'markup', 'documentation']
classifiers = [
"Programming Language :: Python :: 3",
@@ -56,15 +50,10 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.mypy]
-exclude = [
- 'meta/templates/*',
-]
+exclude = ['meta/templates/*']
[tool.flake8]
-exclude = [
- 'meta/templates',
- 'pyhtml/__tags/generated.py',
-]
+exclude = ['meta/templates', 'pyhtml/__tags/generated.py']
per-file-ignores = [
"pyhtml/__tags/input.py:E501",
"pyhtml/__tags/geberated.py:E501",
diff --git a/tests/basic_rendering_test.py b/tests/basic_rendering_test.py
index 2b61dc7..33d6efa 100644
--- a/tests/basic_rendering_test.py
+++ b/tests/basic_rendering_test.py
@@ -208,8 +208,8 @@ def test_flatten_element_lists():
def test_flatten_element_generators():
"""
- If a list of elements is given as a child element, each element should be
- considered as a child.
+ If a generator of elements is given as a child element, each element
+ yielded should be considered as a child.
"""
doc = html(c for c in "hi")
@@ -221,6 +221,21 @@ def test_flatten_element_generators():
])
+def test_flatten_element_other_sequence():
+ """
+ If a tuple of elements is given as a child element, each element should be
+ considered as a child.
+ """
+ doc = html(("h", "i"))
+
+ assert str(doc) == "\n".join([
+ "",
+ " h",
+ " i",
+ "",
+ ])
+
+
def test_classes_can_render():
"""
Can a class by itself be rendered individually?