PythonMonkey icon indicating copy to clipboard operation
PythonMonkey copied to clipboard

Custom lists not working with PythonMonkey

Open Andereoo opened this issue 9 months ago • 0 comments

Issue type

Bug

How did you install PythonMonkey?

Installed from pip

OS platform and distribution

Ubuntu

Python version (python --version)

3.12

PythonMonkey version (pip show pythonmonkey)

1.1.0

Bug Description

Hello! Love this project! I have a Python class inheriting from a list with a couple extra methods and am passing that to JavaScript (see the example below). It seems that my added methods don't exist in JavaScript. If the class inherits from set or tuple it works, but then the value is not ordered anymore. I might be doing something wrong, but any help with this would be hugely appreciated!

Standalone code to reproduce the issue

import pythonmonkey as pm


class Collection(list):
    def item(self):
        print("Do something")
            
pm.eval("(function(pyFunc) { globalThis.document = pyFunc; })")(Collection((1,2,3)))

pm.eval("console.log(document.item())")

Relevant log output or backtrace

Traceback (most recent call last):
  File "/home/andrew/Downloads/TkinterWebBrowser.py", line 10, in <module>
    pm.eval("console.log(document.item())")
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 1, column 22:
TypeError: document.item is not a function
Stack Trace:
  @evaluate:1:22

Additional info if applicable


What branch of PythonMonkey were you developing on? (If applicable)

No response

Andereoo avatar Mar 07 '25 19:03 Andereoo