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

Refactor Python module API to prefer methods over constructors #26695

Merged
merged 3 commits into from
Feb 12, 2025

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Feb 11, 2025

Refactors the Python module API to prefer methods over constructors. The old constructors are still available and still useful in some places, but for the most part users should prefer the new API.

Old style

var interp = new Interpreter();
var mod = new Module(interp, 'mod');
var func = new Function(mod, 'myfunc');

New style

var interp = new Interpreter();
var mod = interp.importModule('mod');
var func = mod.get('myfunc');

This PR also makes a few other changes

  • renamed the internal .get to .getPyObject

  • renamed getAttr/setAttr to get/set

  • renamed getIdx/setIdx to get/set

  • added support for passing kwargs to .call

  • made a variety of doc cleanups/reordered code for better clarity

  • st test/library/packages/Python

  • st test/library/packages/Python with GASNet

[Reviewed by @lydia-duncan]

Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks like a great improvement. I have some comments inline, though most of them are minor

modules/packages/Python.chpl Outdated Show resolved Hide resolved
modules/packages/Python.chpl Outdated Show resolved Hide resolved
modules/packages/Python.chpl Outdated Show resolved Hide resolved
modules/packages/Python.chpl Show resolved Hide resolved
modules/packages/Python.chpl Outdated Show resolved Hide resolved
test/library/packages/Python/examples/torch/myModel.skipif Outdated Show resolved Hide resolved
Copy link
Member

@lydia-duncan lydia-duncan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
@jabraham17
Copy link
Member Author

After fixing the docs build, I followed up with a few more doc improvement tweaks in 9dc61a9

@jabraham17 jabraham17 merged commit 0d1eb5f into chapel-lang:main Feb 12, 2025
9 checks passed
@jabraham17 jabraham17 deleted the py-use-ooo branch February 12, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants