From 0ba26d8f73a415a3e11c64d99a8a8b92fa93adb3 Mon Sep 17 00:00:00 2001 From: sethg Date: Sun, 21 Feb 2021 16:43:36 +0100 Subject: [PATCH] Add property annotations --- Source/Modules/python.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 8c537a527..179375fda 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -2394,6 +2394,23 @@ public: return (ret && funcanno) ? NewStringf(" -> \"%s\"", ret) : NewString(""); } + /* ------------------------------------------------------------ + * returnPropertyAnnotation() + * + * Helper function for constructing a property annotation + * return a empty string for Python 2.x + * ------------------------------------------------------------ */ + + String *returnPropertyAnnotation(Node *n) { + String *ret = 0; + ret = Getattr(n, "type"); + if (ret) { + ret = SwigType_str(ret, 0); + } + return (ret && py3) ? NewStringf(": \"%s\"", ret) + : NewString(""); + } + /* ------------------------------------------------------------ * emitFunctionShadowHelper() * @@ -5042,7 +5059,7 @@ public: String *setname = Swig_name_set(NSPACE_TODO, mname); String *getname = Swig_name_get(NSPACE_TODO, mname); int assignable = is_assignable(n); - Printv(f_shadow, tab4, symname, " = property(", module, ".", getname, NIL); + Printv(f_shadow, tab4, symname, returnPropertyAnnotation(n), " = property(", module, ".", getname, NIL); if (assignable) Printv(f_shadow, ", ", module, ".", setname, NIL); if (have_docstring(n))