From d3d9e9302f5f547cbbb261e8ff08a124e3815dae Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Sun, 24 Mar 2024 19:34:49 +1100 Subject: [PATCH 1/4] Use sequence type for ChildrenType --- pyhtml/__types.py | 4 ++-- pyhtml/__util.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 From 22801d43526e8100e9e82aa9fb80224b3aaf21bb Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Wed, 3 Apr 2024 13:25:47 +1100 Subject: [PATCH 2/4] Bump version to 2.0.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b2c8364..44abb3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyhtml-enhanced" -version = "2.0.0" +version = "2.0.1" description = "A library for building HTML documents with a simple and learnable syntax" authors = ["Miguel Guthridge "] license = "MIT" From eb920784fc7130639df332e0146dcf248eabbdb8 Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Sat, 13 Apr 2024 16:16:05 +1000 Subject: [PATCH 3/4] Bump version to 2.0.2 --- pyproject.toml | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) 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", From 060cf45612c482cb3232a76474256838e4181b87 Mon Sep 17 00:00:00 2001 From: Miguel Guthridge Date: Sat, 13 Apr 2024 16:30:15 +1000 Subject: [PATCH 4/4] Fix code coverage --- tests/basic_rendering_test.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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?