Skip to content

Element.append() is not working with strings #2418

@jolaf

Description

@jolaf

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

Element.append() should allow appending not only other Elements, but strings too.
It works for JS objects, but crashes for PyScript objects.

To reproduce: https://jolaf.pyscriptapps.com/test/latest/

What browsers are you seeing the problem on? (if applicable)

Chrome

Console info

Traceback (most recent call last):
  File "/home/pyodide/pyscript/web.py", line 69, in append
    try:A.tagName;B._dom_element.appendChild(A)
        ^^^^^^^^^
AttributeError: 'str' object has no attribute 'tagName'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pyodide/pyscript/web.py", line 72, in append
    A.length
AttributeError: 'str' object has no attribute 'length'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/lib/python313.zip/_pyodide/_base.py", line 597, in eval_code_async
    await CodeRunner(
    ...<9 lines>...
    .run_async(globals, locals)
  File "/lib/python313.zip/_pyodide/_base.py", line 411, in run_async
    coroutine = eval(self.code, globals, locals)
  File "<exec>", line 5, in <module>
  File "/home/pyodide/pyscript/web.py", line 74, in append
    except AttributeError:G=f'Element "{A}" is a proxy object, "but not a valid element or a NodeList.';raise TypeError(G)
                                                                                                        ^^^^^^^^^^^^^^^^^^
TypeError: Element "Python object append OK" is a proxy object, "but not a valid element or a NodeList.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions