Skip to content

Conversation

@XuehaiPan
Copy link
Member

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 #15213 if this solves the issue #15213

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide. (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly. (required for a bug fix or a new feature)
  • I have updated the documentation accordingly.
  • I have reformatted the code using make format. (required)
  • I have checked the code using make lint. (required)
  • I have ensured make test pass. (required)

@XuehaiPan XuehaiPan requested a review from Copilot January 2, 2026 08:09
@XuehaiPan XuehaiPan self-assigned this Jan 2, 2026
@XuehaiPan XuehaiPan added the cxx Something related to the CXX source code label Jan 2, 2026
@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (05691e7) to head (1c36af1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #263   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           14        14           
  Lines         1416      1416           
  Branches       175       175           
=========================================
  Hits          1416      1416           
Flag Coverage Δ
unittests 100.00% <ø> (ø)
unittests-cp310-Linux 100.00% <ø> (ø)
unittests-cp310-Windows 100.00% <ø> (ø)
unittests-cp310-macOS 100.00% <ø> (ø)
unittests-cp311-Linux 100.00% <ø> (ø)
unittests-cp311-Windows 100.00% <ø> (ø)
unittests-cp311-macOS 100.00% <ø> (ø)
unittests-cp312-Linux 100.00% <ø> (ø)
unittests-cp312-Windows 100.00% <ø> (ø)
unittests-cp312-macOS 100.00% <ø> (ø)
unittests-cp313-Linux 100.00% <ø> (ø)
unittests-cp313-Windows 100.00% <ø> (ø)
unittests-cp313-macOS 100.00% <ø> (ø)
unittests-cp313t-Linux 100.00% <ø> (ø)
unittests-cp313t-Windows 100.00% <ø> (ø)
unittests-cp313t-macOS 100.00% <ø> (ø)
unittests-cp314-Linux 100.00% <ø> (ø)
unittests-cp314-Windows 100.00% <ø> (ø)
unittests-cp314-macOS 100.00% <ø> (ø)
unittests-cp314t-Linux 100.00% <ø> (ø)
unittests-cp314t-Windows 100.00% <ø> (ø)
unittests-cp314t-macOS 100.00% <ø> (ø)
unittests-cp39-Linux 100.00% <ø> (ø)
unittests-cp39-Windows 100.00% <ø> (ø)
unittests-cp39-macOS 100.00% <ø> (ø)
unittests-pp311-Linux 100.00% <ø> (ø)
unittests-pp311-Windows 100.00% <ø> (ø)
unittests-pp311-macOS 100.00% <ø> (ø)
unittests-pydebug 100.00% <ø> (ø)
unittests-pydebug-cp310d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp310d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp310d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp311d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp311d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp311d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp312d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp312d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp312d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp313d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp313d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp313d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp313td-Linux 100.00% <ø> (ø)
unittests-pydebug-cp313td-Windows 100.00% <ø> (ø)
unittests-pydebug-cp313td-macOS 100.00% <ø> (ø)
unittests-pydebug-cp314d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp314d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp314d-macOS 100.00% <ø> (ø)
unittests-pydebug-cp314td-Linux 100.00% <ø> (ø)
unittests-pydebug-cp314td-Windows 100.00% <ø> (ø)
unittests-pydebug-cp314td-macOS 100.00% <ø> (ø)
unittests-pydebug-cp39d-Linux 100.00% <ø> (ø)
unittests-pydebug-cp39d-Windows 100.00% <ø> (ø)
unittests-pydebug-cp39d-macOS 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Copilot AI left a 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 refactors the codebase to remove the custom Py_Get_ID macro system and cached string objects, replacing them with direct string literals. This simplifies the code by eliminating the need for string object caching and macro-based string handling.

  • Removed all Py_Declare_ID and Py_Get_ID macro definitions from include/optree/pymacros.h
  • Replaced Py_Get_ID() calls with direct string literals in pybind11 functions (py::getattr, py::setattr) and C API functions (PyObject_GetAttrString)
  • Updated all affected files to use the simplified string handling approach

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/optree/pymacros.h Removed all Py_Declare_ID and Py_Get_ID macro definitions and cached string declarations
src/optree.cpp Replaced Py_Get_ID with py::str() for module attribute setting
include/optree/pytypes.h Replaced Py_Get_ID with PyObject_GetAttrString for C API calls and direct strings for py::getattr calls
src/treespec/treespec.cpp Replaced Py_Get_ID(copy) with direct string "copy" in py::getattr calls
src/treespec/serialization.cpp Replaced Py_Get_ID with direct strings for __name__, __module__, __qualname__ attribute access
src/treespec/flatten.cpp Replaced Py_Get_ID with direct strings for copy, default_factory, and maxlen attribute access
src/treespec/constructors.cpp Replaced Py_Get_ID with direct strings for copy, default_factory, and maxlen attribute access

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@XuehaiPan XuehaiPan merged commit 975ccf5 into metaopt:main Jan 2, 2026
316 of 342 checks passed
@XuehaiPan XuehaiPan deleted the remove-cached-strings branch January 2, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cxx Something related to the CXX source code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant