Skip to content

Commit

Permalink
feat(treespec): set enum type immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
XuehaiPan committed Oct 28, 2023
1 parent ae03919 commit fd156b6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/optree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,17 @@ void BuildModule(py::module& mod) { // NOLINT[runtime/references]
#ifdef Py_TPFLAGS_IMMUTABLETYPE
reinterpret_cast<PyTypeObject*>(PyTreeSpecTypeObject.ptr())->tp_flags |=
Py_TPFLAGS_IMMUTABLETYPE;
reinterpret_cast<PyTypeObject*>(PyTreeKindTypeObject.ptr())->tp_flags |=
Py_TPFLAGS_IMMUTABLETYPE;
#endif
if (PyType_Ready(reinterpret_cast<PyTypeObject*>(PyTreeSpecTypeObject.ptr())) < 0)
[[unlikely]] {
INTERNAL_ERROR("`PyType_Ready(&PyTreeSpec_Type)` failed.");
}
if (PyType_Ready(reinterpret_cast<PyTypeObject*>(PyTreeKindTypeObject.ptr())) < 0)
[[unlikely]] {
INTERNAL_ERROR("`PyType_Ready(&PyTreeKind_Type)` failed.");
}
}

} // namespace optree
Expand Down

0 comments on commit fd156b6

Please sign in to comment.