Introduce detail::annotated_any() helper.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2023-11-16 12:31:13 -08:00
parent 429a1f820d
commit 2b2ffebeb8
2 changed files with 6 additions and 4 deletions

View File

@ -1201,13 +1201,17 @@ protected:
static Constructor make_move_constructor(...) { return nullptr; } static Constructor make_move_constructor(...) { return nullptr; }
}; };
inline std::string annotated_any(const std::string &cpp_type) {
return "Annotated[Any, \"" + cpp_type + "\"]";
}
PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) { PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) {
if (auto *type_data = get_type_info(ti)) { if (auto *type_data = get_type_info(ti)) {
handle th((PyObject *) type_data->type); handle th((PyObject *) type_data->type);
return th.attr("__module__").cast<std::string>() + '.' return th.attr("__module__").cast<std::string>() + '.'
+ th.attr("__qualname__").cast<std::string>(); + th.attr("__qualname__").cast<std::string>();
} }
return "Annotated[Any, \"" + clean_type_id(ti.name()) + "\"]"; return annotated_any(clean_type_id(ti.name()));
} }
PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(detail)

View File

@ -492,9 +492,7 @@ protected:
signature += rec->scope.attr("__module__").cast<std::string>() + "." signature += rec->scope.attr("__module__").cast<std::string>() + "."
+ rec->scope.attr("__qualname__").cast<std::string>(); + rec->scope.attr("__qualname__").cast<std::string>();
} else { } else {
std::string tname(t->name()); signature += detail::annotated_any(detail::clean_type_id(t->name()));
detail::clean_type_id(tname);
signature += "Annotated[Any, \"" + tname + "\"]";
} }
} else { } else {
signature += c; signature += c;