Skip to content

Add support for callable class instances #494

@CarrJames

Description

@CarrJames

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions