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

[Feature Request]: Support Python operators on Python.Value #26911

Open
jabraham17 opened this issue Mar 12, 2025 · 0 comments
Open

[Feature Request]: Support Python operators on Python.Value #26911

jabraham17 opened this issue Mar 12, 2025 · 0 comments

Comments

@jabraham17
Copy link
Member

Currently, the way to call Python operators from Chapel is to explicitly call the dunder method

use Python;
var interp = new Interpreter();
var pyInt1 = interp.toPython(10);
var pyInt2 = interp.toPython(11);

var res = pyInt1.call("__add__", pyInt2);

While this is a simple/silly example with plain integers, many libraries overload these dunder methods in interesting ways to create their user interfaces. Translitering these libraries in Chapel-Python interop can be awkward because of these dunder method calls.

However, we could support many of these Python operators as Chapel operators. For example

operator +(lhs: owned Value, rhs: owned Value) {
  return lhs.call("__add__", rhs);
}

I think we should support as many of these dunder methods as we can

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

No branches or pull requests

1 participant