Skip to content

Commit

Permalink
Introduce detail::annotated_any() helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Nov 16, 2023
1 parent 429a1f8 commit 2b2ffeb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1201,13 +1201,17 @@ class type_caster_base : public type_caster_generic {
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<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)
Expand Down
4 changes: 1 addition & 3 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ class cpp_function : public function {
signature += rec->scope.attr("__module__").cast<std::string>() + "."
+ rec->scope.attr("__qualname__").cast<std::string>();
} 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;
Expand Down

0 comments on commit 2b2ffeb

Please sign in to comment.