Improved our JavaScript and Python bindings#558
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the JavaScript and Python language bindings by adding Pythonic/JavaScript-idiomatic interfaces on top of the existing C++-style API: vectors exposed to JS now expose .length and are iterable (so callers can use for..of, spread, etc. instead of .size()/.get(i)); Python File, FileManager, SedInstance, Issue, and Solver types get __repr__/__str__/__len__/__iter__ where appropriate. The test suites are updated to use these more idiomatic patterns, replacing == True/== False/== None with truthiness/is None checks and replacing .size() with .length.
Changes:
- Add
__repr__,__str__,__len__, and__iter__bindings to relevant Python classes; addtoStringand array-like.length+Symbol.iteratorto relevant JS classes. - Update Python tests to use truthiness /
is None/is not Noneand new iteration helpers (len(instance),list(instance),len(file_manager),list(file_manager)). - Update JS tests and example script to use
.lengthandfor..ofover registered vector types.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| VERSION.txt | Bumps patch version. |
| src/bindings/python/file.cpp | Adds __repr__ to File and __len__/__iter__ to FileManager. |
| src/bindings/python/logger.cpp | Adds __repr__/__str__ to Issue. |
| src/bindings/python/sed.cpp | Adds __len__/__iter__ to SedInstance. |
| src/bindings/python/solver.cpp | Adds __repr__ to Solver. |
| src/bindings/javascript/logger.cpp | Adds toString() to Issue. |
| src/bindings/javascript/solver.cpp | Adds toString() to Solver. |
| src/bindings/javascript/main.cpp | Adds length getter and Symbol.iterator to all registered vector types via EM_ASM. |
| tests/bindings/python/test_*.py | Switches assertions to idiomatic truthiness / is None and exercises new iter/len. |
| tests/bindings/python/test_logger_coverage.py | Adds test_issue_str covering __str__. |
| tests/bindings/javascript/*.test.js | Switches .size() to .length and adds toString() test. |
| tests/bindings/javascript/utils.in.js | Uses Array.from(issues).entries() instead of indexed access. |
| tests/bindings/javascript/res/res/libopencor.js | Uses for..of over issues and files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b604a4d to
1c9df90
Compare
Added `__iter__()`, `__len__()`, `__repr__()`, and `__str__()` wherever it makes sense.
No description provided.