Skip to content

Commit 54627fe

Browse files
Merge branch 'main' of github.com:COMP1010UNSW/pyhtml-enhanced
2 parents 9a0bca9 + b0c54c1 commit 54627fe

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

pyhtml/__types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Type definitions
55
"""
66
from typing import Union, TYPE_CHECKING
7-
from collections.abc import Generator
7+
from collections.abc import Generator, Sequence
88

99

1010
if TYPE_CHECKING:
@@ -33,7 +33,7 @@
3333

3434
ChildrenType = Union[
3535
ChildElementType,
36-
list[ChildElementType],
36+
Sequence[ChildElementType],
3737
'Generator[ChildElementType, None, None]',
3838
# TODO: Would an `Any` type for the generator return be better, even though
3939
# it would be discarded?

pyhtml/__util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Random helpful functions used elsewhere
55
"""
66
from typing import Any, TypeVar
7-
from collections.abc import Generator
7+
from collections.abc import Generator, Sequence
88
from .__types import ChildrenType, ChildElementType
99

1010

@@ -143,6 +143,10 @@ def flatten_list(the_list: list[ChildrenType]) -> list[ChildElementType]:
143143
result.extend(item)
144144
elif isinstance(item, Generator):
145145
result.extend(item)
146+
elif isinstance(item, str):
147+
result.append(item)
148+
elif isinstance(item, Sequence):
149+
result.extend(item)
146150
else:
147151
result.append(item)
148152
return result

pyproject.toml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
[tool.poetry]
22
name = "pyhtml-enhanced"
3-
version = "2.0.1"
3+
version = "2.0.2"
44
description = "A library for building HTML documents with a simple and learnable syntax"
55
authors = ["Miguel Guthridge <miguel.guthridge@unsw.edu.au>"]
66
license = "MIT"
77
readme = "README.md"
8-
packages = [{include = "pyhtml"}]
8+
packages = [{ include = "pyhtml" }]
99

1010
repository = "https://github.com/COMP1010UNSW/pyhtml-enhanced"
1111
documentation = "https://github.com/COMP1010UNSW/pyhtml-enhanced#README"
1212

13-
keywords = [
14-
'html',
15-
'template',
16-
'pyhtml',
17-
'markup',
18-
'documentation',
19-
]
13+
keywords = ['html', 'template', 'pyhtml', 'markup', 'documentation']
2014

2115
classifiers = [
2216
"Programming Language :: Python :: 3",
@@ -56,15 +50,10 @@ requires = ["poetry-core"]
5650
build-backend = "poetry.core.masonry.api"
5751

5852
[tool.mypy]
59-
exclude = [
60-
'meta/templates/*',
61-
]
53+
exclude = ['meta/templates/*']
6254

6355
[tool.flake8]
64-
exclude = [
65-
'meta/templates',
66-
'pyhtml/__tags/generated.py',
67-
]
56+
exclude = ['meta/templates', 'pyhtml/__tags/generated.py']
6857
per-file-ignores = [
6958
"pyhtml/__tags/input.py:E501",
7059
"pyhtml/__tags/geberated.py:E501",

tests/basic_rendering_test.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ def test_flatten_element_lists():
208208

209209
def test_flatten_element_generators():
210210
"""
211-
If a list of elements is given as a child element, each element should be
212-
considered as a child.
211+
If a generator of elements is given as a child element, each element
212+
yielded should be considered as a child.
213213
"""
214214
doc = html(c for c in "hi")
215215

@@ -221,6 +221,21 @@ def test_flatten_element_generators():
221221
])
222222

223223

224+
def test_flatten_element_other_sequence():
225+
"""
226+
If a tuple of elements is given as a child element, each element should be
227+
considered as a child.
228+
"""
229+
doc = html(("h", "i"))
230+
231+
assert str(doc) == "\n".join([
232+
"<html>",
233+
" h",
234+
" i",
235+
"</html>",
236+
])
237+
238+
224239
def test_classes_can_render():
225240
"""
226241
Can a class by itself be rendered individually?

0 commit comments

Comments
 (0)