File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,23 @@ static PyMethodDef tp_methods_impl[]
4545 nullptr },
4646 {nullptr , nullptr , 0 , nullptr }};
4747
48+ // Python 3.12+ emits a DeprecationWarning for heap types whose tp_name does
49+ // not contain a dot ('.') and that lack a __module__ attribute. For pybind11's
50+ // internal function_record type, we do not have an actual module object to
51+ // attach, so we cannot use PyType_FromModuleAndSpec (introduced in Python 3.9)
52+ // to set __module__ automatically.
53+ //
54+ // As a workaround, we define a "qualified" type name that includes a dummy
55+ // module name (PYBIND11_DUMMY_MODULE_NAME). This is non‑idiomatic but avoids
56+ // the deprecation warning, and results in reprs like
57+ //
58+ // <class 'pybind11_builtins.pybind11_detail_function_record_...'>
59+ //
60+ // even though no real pybind11_builtins module exists. If pybind11 gains an
61+ // actual module object in the future, this code should switch to
62+ // PyType_FromModuleAndSpec for Python 3.9+ and drop the dummy module
63+ // workaround.
64+ //
4865// Note that this name is versioned.
4966#define PYBIND11_DETAIL_FUNCTION_RECORD_TP_PLAINNAME \
5067 " pybind11_detail_function_record_" PYBIND11_DETAIL_FUNCTION_RECORD_ABI_ID \
You can’t perform that action at this time.
0 commit comments