From 11040768ca17bbbd8a7ad31310f455b5ea2aaf66 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 14 Nov 2023 13:50:20 -0800 Subject: [PATCH] Add `Annotated[Any, "..."]` wrapping in `type_info_description()` --- include/pybind11/detail/type_caster_base.h | 2 +- tests/test_cases_for_stubgen.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 476646ee8..77f3d4790 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -1207,7 +1207,7 @@ PYBIND11_NOINLINE std::string type_info_description(const std::type_info &ti) { return th.attr("__module__").cast() + '.' + th.attr("__qualname__").cast(); } - return clean_type_id(ti.name()); + return "Annotated[Any, \"" + clean_type_id(ti.name()) + "\"]"; } PYBIND11_NAMESPACE_END(detail) diff --git a/tests/test_cases_for_stubgen.py b/tests/test_cases_for_stubgen.py index 8ca2acead..e57e038ce 100644 --- a/tests/test_cases_for_stubgen.py +++ b/tests/test_cases_for_stubgen.py @@ -21,15 +21,15 @@ from pybind11_tests import stl as test_stl ), ( m.MapIntUserType.values.__doc__, - "values(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ValuesView[test_cases_for_stubgen::user_type]\n", + 'values(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ValuesView[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n', ), ( m.MapIntUserType.items.__doc__, - "items(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ItemsView[int, test_cases_for_stubgen::user_type]\n", + 'items(self: pybind11_tests.cases_for_stubgen.MapIntUserType) -> pybind11_tests.cases_for_stubgen.ItemsView[int, Annotated[Any, "test_cases_for_stubgen::user_type"]]\n', ), ( m.MapUserTypeInt.keys.__doc__, - "keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.KeysView[test_cases_for_stubgen::user_type]\n", + 'keys(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.KeysView[Annotated[Any, "test_cases_for_stubgen::user_type"]]\n', ), ( m.MapUserTypeInt.values.__doc__, @@ -37,7 +37,7 @@ from pybind11_tests import stl as test_stl ), ( m.MapUserTypeInt.items.__doc__, - "items(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.ItemsView[test_cases_for_stubgen::user_type, int]\n", + 'items(self: pybind11_tests.cases_for_stubgen.MapUserTypeInt) -> pybind11_tests.cases_for_stubgen.ItemsView[Annotated[Any, "test_cases_for_stubgen::user_type"], int]\n', ), ( m.MapFloatUserType.keys.__doc__,