pull in get_module_name_if_available() (pytypes.h)

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-31 14:33:04 -07:00
parent cae3cf99b6
commit e6c74dfef4

View File

@ -2604,5 +2604,18 @@ PYBIND11_MATH_OPERATOR_BINARY_INPLACE(operator>>=, PyNumber_InPlaceRshift)
#undef PYBIND11_MATH_OPERATOR_BINARY
#undef PYBIND11_MATH_OPERATOR_BINARY_INPLACE
// Meant to return a Python str, but this is not checked.
inline object get_module_name_if_available(handle scope) {
if (scope) {
if (hasattr(scope, "__module__")) {
return scope.attr("__module__");
}
if (hasattr(scope, "__name__")) {
return scope.attr("__name__");
}
}
return object();
}
PYBIND11_NAMESPACE_END(detail)
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)