Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyhtml/__types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 5 additions & 1 deletion pyhtml/__util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
21 changes: 5 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <miguel.guthridge@unsw.edu.au>"]
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",
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 17 additions & 2 deletions tests/basic_rendering_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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([
"<html>",
" h",
" i",
"</html>",
])


def test_classes_can_render():
"""
Can a class by itself be rendered individually?
Expand Down