COMP1010UNSW / pyhtml-enhanced

A library for building HTML documents with a simple and learnable syntax
https://comp1010unsw.github.io/pyhtml-enhanced/
MIT License
4 stars 1 forks source link

Add type constraints to children and attributes for tags #19

Closed MaddyGuthridge closed 7 months ago

MaddyGuthridge commented 9 months ago

Currently, PyHTML accepts any data as an argument for an element. Although this is technically true, as all data will be stringified before being rendered, using certain types often leads to garbled output.

>>> import pyhtml as p
>>> str(p.p({ "i": p.i("italics"), "b": p.b("bold") }))
'<p>\n  {&#x27;i&#x27;: &lt;i&gt;\n  italics\n&lt;/i&gt;, &#x27;b&#x27;: &lt;b&gt;\n  bold\n&lt;/b&gt;}\n</p>'

We should add constraints to these argument types so that static analysis tools can prevent users from unintentionally writing this (often unintentional) code.

MaddyGuthridge commented 7 months ago

Planning to add better error messages for this