posit-dev / py-htmltools

Tools for HTML generation and output
MIT License
19 stars 4 forks source link

Better typing for TagChildArg #11

Closed wch closed 2 years ago

wch commented 2 years ago

For TagChildArg, the Iterable["TagChildArg"] is too permissive, because it allows sets and dicts. For example, the type checker doesn't flag these, but these result in run-time errors:

div({"a", "b"})
#> TypeError: Invalid tag child type: <class 'set'>. Consider calling str() on this value be fore treating it as a tag child.

div({"a": "a"})
#> TypeError: Invalid tag child type: <class 'dict'>. Consider calling str() on this value b efore treating it as a tag child.
wch commented 2 years ago

One note: the reason I used Dict and Tuple instead of just Sequence, is because a range() counts a Sequence, but if you try to use one in a tag, it results in an error.