COMP1010UNSW / pyhtml-enhanced

Build HTML documents in Python with a simple and learnable syntax
https://comp1010unsw.github.io/pyhtml-enhanced/
MIT License
4 stars 1 forks source link

Type safety issues when using a list of children #40

Closed MaddyGuthridge closed 6 months ago

MaddyGuthridge commented 7 months ago

To reproduce:

list_items = [p.li("a"), p.li("b")]
p.ul(list_items)

From pylance:

Argument of type "list[li]" cannot be assigned to parameter "children" of type "ChildrenType" in function "__init__"
  Type "list[li]" cannot be assigned to type "ChildrenType"
    "list[li]" is incompatible with "Tag"
    Type "list[li]" cannot be assigned to type "type[Tag]"
    "list[li]" is incompatible with "str"
    "list[li]" is incompatible with "list[ChildElementType]"
      Type parameter "_T@list" is invariant, but "li" is not the same as "ChildElementType"
      Consider switching from "list" to "Sequence" which is covariant
    "list[li]" is incompatible with "Generator[ChildElementType, None, None]"

Need to check if this is also an issue in mypy.

Sadly switching to Sequnce is not going to work since that covers a number of other types that are intentionally incompatible.