-
Notifications
You must be signed in to change notification settings - Fork 12
feat(registry): add support for method pair (__tree_flatten__, __tree_unflatten__)
#253
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #253 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 1403 1416 +13
Branches 173 175 +2
=========================================
+ Hits 1403 1416 +13 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the pytree node registration API to use dunder-style method names (__tree_flatten__ and __tree_unflatten__) instead of the legacy method names (tree_flatten and tree_unflatten). The change maintains backward compatibility by automatically wrapping legacy methods with dunder-style versions.
- Implements automatic wrapping of legacy method names to new dunder-style names for backward compatibility
- Updates the
CustomTreeNodeprotocol to require dunder-style methods - Adds comprehensive test coverage for the new behavior, including tests for legacy methods, mixed styles, and missing methods
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| optree/registry.py | Adds backward compatibility logic to wrap legacy tree_flatten/tree_unflatten methods as __tree_flatten__/__tree_unflatten__, includes version notes |
| optree/typing.py | Updates CustomTreeNode protocol to use dunder-style method names and adds TREE_PATH_ENTRY_TYPE class variable |
| optree/functools.py | Updates partial class methods to use dunder-style names |
| tests/test_registry.py | Updates existing tests to use dunder-style names and adds three new comprehensive test functions for legacy method support, missing methods, and wrapping behavior |
| tests/test_treespec.py | Updates test class methods to use dunder-style names |
| tests/test_dataclasses.py | Updates test class methods to use dunder-style names |
| tests/test_accessors.py | Updates test class methods to use dunder-style names |
| tests/helpers.py | Updates helper class methods to use dunder-style names |
| README.md | Updates documentation examples to use dunder-style method names |
| docs/source/spelling_wordlist.txt | Adds "dunder" to the spelling wordlist |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b8d5b69 to
28deee1
Compare
7d6688d to
1a99134
Compare
4c694e6 to
e9f5b15
Compare
e9f5b15 to
84f805d
Compare
Description
Describe your changes in detail.
Motivation and Context
Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax
close #15213if this solves the issue #15213Resolves #252
Types of changes
What types of changes does your code introduce? Put an
xin all the boxes that apply:Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!
make format. (required)make lint. (required)make testpass. (required)