Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for static class methods #368

Open
olebedev opened this issue Jun 20, 2024 · 2 comments
Open

Add support for static class methods #368

olebedev opened this issue Jun 20, 2024 · 2 comments

Comments

@olebedev
Copy link

olebedev commented Jun 20, 2024

Describe your feature request here.

Currently, when you define JS like this:

var Term = class {
  term;

  constructor(term) {
    this.term = term;
  }

  toString() {
    return this.term;
  }

  static fromString(input) {
    return new Term(input);
  }
};

module.exports = Term;

The static method is not available for that class:

import pythonmonkey as pm

Term = pm.require("./term.js")
print(Term.fromString)

Will give

Traceback (most recent call last):
  File "/test.py", line 4, in <module>
    print(Term.fromString)
AttributeError: 'pythonmonkey.JSFunctionProxy' object has no attribute 'fromString'

Code example

No response

@wiwichips
Copy link
Collaborator

Thanks for the bug report @olebedev - we're looking into this

@wiwichips
Copy link
Collaborator

wiwichips commented Jul 2, 2024

In the meantime before it's fixed, if you need this behaviour, you can accomplish it through pm.eval

For example:

import pythonmonkey as pm

def js_static_class_prop(js_class, prop):
    return pm.eval('(c,p) => c[p]')(js_class, prop)

Term = pm.require("./term.js")
print(js_static_class_prop(Term, "fromString")) # <pythonmonkey.JSFunctionProxy object at 0x7fa038909570>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

No branches or pull requests

2 participants