From 9f34dccdb843362af2c981a3fa66463e96e3027e Mon Sep 17 00:00:00 2001 From: Michael Carlstrom Date: Thu, 5 Dec 2024 14:20:43 -0500 Subject: [PATCH] test writing __annotations__ to __dict__ --- include/pybind11/pytypes.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 6606b7c03..ee8cc82bf 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -2567,7 +2567,13 @@ str_attr_accessor object_api::doc() const { template str_attr_accessor object_api::annotations() const { - str_attr_accessor annotations_dict = attr("__annotations__"); + // Create dict automatically + + #if !defined(PYPY_VERSION) && PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION <= 9 + str_attr_accessor annotations_dict = attr("__dict__").attr("__annotations__"); + #else + str_attr_accessor annotations_dict = attr("__annotations__"); + #endif // Create dict automatically if (!isinstance(annotations_dict)) { annotations_dict = dict();