Uh oh!
There was an error while loading. Please reload this page.
Enable specifyingpy::metaclass(PyType_Type) without a C/C++ cast. - #5015
Enable specifyingpy::metaclass(PyType_Type) without a C/C++ cast.#5015rwgk wants to merge 6 commits into
py::metaclass(PyType_Type) without a C/C++ cast.#5015Conversation
wjakob
commented
Feb 1, 2024
This seems quite benign as a change. But I think it could be useful to add somewhere in the docs that types can be specified this way, and that the basic PyType_Type metaclass has some friction points but offers compatibility to ABCMeta. |
7318d76 to
dfe3eacComparedfe3eac to
cf230fbComparerwgk
commented
Feb 1, 2024
Done: cf230fb |
Is "and can also lead to other surprising issues" appropriate given that is text that users will read in the documentation? It seems a bit like fear-mongering that pybind11 is doing something bad by default. Whereas the default metaclass works perfectly fine except in fairly narrow niche cases that you seem to be running into in the Google ecosystem (nobody had ever brought up the issue you raised before). And there are good technical reasons why it this custom metaclass is used. I think it's also worth pointing out in the docstring that if compatibility with |
5b7ebd7 to
0d29c62Comparerwgk
commented
Feb 2, 2024
I replaced "issues" (which I understood as something that simply needs attention) with "side effects" (the evidence is in the PR description; I'm not mentioning #1359 because I don't understand it enough, but there is a good chance that it is also related).
I did already (although I had accidentally left out one |
rwgk
commented
Feb 2, 2024
I just converted this PR back to Draft mode because we (@Yhg1s and myself) just decided that PyCLIF-pybind11 will use the default pybind11 metaclass, and that we'll change client code to make that possible (sprawling changes around the Google code base). How exactly I'm still figuring out. The main idea is to use a metaclass that has both |
The default pybind11 metaclass pretends that it lives in module A module with the name I wouldn't call that bad, but it does not look right either, especially because it is why MATLAB is falling over: We need do consider: there may be multiple ABI-incompatible metaclasses in a given process. We cannot simply create a Or could we? — By ensuring that Or could/should we add the ABI key to the name? (e.g. |
rwgk
commented
Feb 2, 2024
Pretty certain: we cannot. Because |
Description
py::metaclass(PyType_Type)is useful to resolve these problems:metaclass conflictin the added tests.This PR makes it possible to simply specify
py::metaclass(PyType_Type)instead ofpy::metaclass((PyObject *) &PyType_Type).This PR also adds comments regarding abc.ABCMeta compatibility.
Note for completeness: the added tests are a partial backport from google/pywrapcc#30094.
Suggested changelog entry:
It is now possible to specify ``py::metaclass(PyType_Type)`` without a C/C++ cast.