diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 77f3d4790..1b3762167 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -1201,13 +1201,17 @@ protected: 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) { if (auto *type_data = get_type_info(ti)) { handle th((PyObject *) type_data->type); return th.attr("__module__").cast() + '.' + th.attr("__qualname__").cast(); } - return "Annotated[Any, \"" + clean_type_id(ti.name()) + "\"]"; + return annotated_any(clean_type_id(ti.name())); } PYBIND11_NAMESPACE_END(detail) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 33ad041fd..84b415a68 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -492,9 +492,7 @@ protected: signature += rec->scope.attr("__module__").cast() + "." + rec->scope.attr("__qualname__").cast(); } else { - std::string tname(t->name()); - detail::clean_type_id(tname); - signature += "Annotated[Any, \"" + tname + "\"]"; + signature += detail::annotated_any(detail::clean_type_id(t->name())); } } else { signature += c;