Skip to content
goldstar611 edited this page Oct 6, 2021 · 2 revisions

Magic method allowing custom objects to use brythonic <= and + operators

Suggestion

A magic dunder method providing a DOMNode view of the object (e.g. object.__as_node__() -> DOMNode) allowing objects to be used by the <= and + operators as DOMNodes.

This could be __as_node__ or any other acceptable method name.

Background

The brythonic child (<=) and sibling (+) operators are used to easily construct DOM trees.

A discussion concerning this feature is on the google group

Reasoning

This suggestion improves brython in the following ways:

  1. Fixes clumsy syntax (e.g. Object.attach(DOMNode)) which <= was meant to avoid in brython
  2. Objects that wrap DOMNodes could now be used transparently as DOMNodes
  3. Slow python function calls (e.g. Object.attach(DOMNode)) would be replaced with faster javascript
  • Testing demonstrated nearly double the speed for comparable operations. ###Status: Superseded###

Instead the functions in browser.html were replaced with objects that can be subclassed. This naturally allows the <= grammar to be used with these children.