Skip to content

Consider defining Node as a union type that includes collections, and getting rid of Text and Fragment #55

@davepeck

Description

@davepeck

For developers familiar with typing in the React world, React.ReactNode can be both a singleton or a collection. We should consider doing the same:

type Node = Element | Comment | DocumentType | str | Iterable[Node]

Now that we build on top of MarkupSafe, Text serves less of a purpose. We could get rid of it in favor of just “str”, probably. Likewise, Fragment is basically an Iterable[Node].

The benefit is simpler typing for developers: in components, for example, they can type children as Node rather than Iterable[Node].

The drawback is that you can't just str(some_node) to render it anymore; you'd need to call a new top-level tdom.render() method.

I don't know which is preferable overall.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions