-
Notifications
You must be signed in to change notification settings - Fork 2.2k
docs: Add a note about calling Python C APIs on py::native_enum
#5640
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
|
||
The enum types created by ``py::native_enum`` are native Python types, while | ||
the enum types created by the older ``py::enum_`` are C++ pybind11 types. | ||
Developers **SHOULD NOT** call ``PyType_*`` Python C APIs on the enum types |
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.
First impression: I'm very confused.
Could you please explain more? E.g. provide an example of what exactly one might want to do with PyType_*
?
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.
I added a comment here: https://github.com/metaopt/optree/pull/214/files#r2078078711
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.
Please do not merge the current version. See my comments.
At the moment I'm thinking: What the optree codes does, no one should ever do, for any type they don't own.
I added a comment in metaopt/optree#214 (comment). The problem is that I used the |
It was eye-opening to see how difficult it is to decide "can I include pybind11/native_enum.h"? I added a reminder to fix that to #5589 |
Description
Add a note about calling Python C APIs on
py::native_enum
in the documentation.Developers should never call
PyType_*
Python C APIs on the enum types created bypy:native_enum
, which can cause unexpected issues.See also:
pybind11::native_enum
to create enum classPyTreeKind
metaopt/optree#214Suggested changelog entry:
Add a note about calling Python C APIs on `py::native_enum` in the documentation.