PythonMonkey icon indicating copy to clipboard operation
PythonMonkey copied to clipboard

Add support for callable class instances

Open CarrJames opened this issue 7 months ago • 0 comments

Describe your feature request here.

Attempting to call an instance of a class with a __call__ method within JS produces the following error:

TypeError: [object name] is not a function

Callable objects can be detected using PyCallable_Check()

Code example

import pythonmonkey as pm

def test_func():
    print("test_func")

class test_class:
    def __call__(self):
        print("test_class")

globalThis = pm.eval("globalThis;")
globalThis.test_func = test_func
globalThis.test_class_instance = test_class()

pm.eval("globalThis.test_func()") # This works
pm.eval("globalThis.test_class_instance()") # This does not work

Stack Trace

Traceback (most recent call last):
  File "[PATH TO FILE].py", line 17, in <module>
    pm.eval("globalThis.test_class_instance()") # This does not work
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pythonmonkey.SpiderMonkeyError: Error in file evaluate, on line 1, column 12:
TypeError: globalThis.test_class_instance is not a function
Stack Trace:
  @evaluate:1:12

CarrJames avatar Jul 15 '25 13:07 CarrJames