From 3159de3e9fcd8b7bf8747711fe240a36d620075f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Mar 2022 19:33:03 +0000 Subject: [PATCH] Add support for Python variable annotations as a feature. Both function annotations and variable annotations are turned on using the "python:annotations" feature. Example: %feature("python:annotations", "c"); struct V { float val; }; The generated code contains a variable annotation containing the C float type: class V(object): val: "float" = property(_example.V_val_get, _example.V_val_set) ... Python 3.5 and earlier do not support variable annotations, so variable annotations can be turned off with a "python:annotations:novar" feature flag. Example turning on function annotations but not variable annotations globally: %feature("python:annotations", "c"); %feature("python:annotations:novar"); or via the command line: -features python:annotations=c,python:annotations:novar Closes #1951 --- CHANGES.current | 33 ++++++++ Doc/Manual/Contents.html | 2 +- Doc/Manual/Python.html | 76 ++++++++++++++++--- Examples/test-suite/python/Makefile.in | 1 + .../python_annotations_variable_c_runme.py | 24 ++++++ .../python_annotations_variable_c.i | 44 +++++++++++ Source/Modules/python.cxx | 26 ++++--- 7 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 Examples/test-suite/python/python_annotations_variable_c_runme.py create mode 100644 Examples/test-suite/python_annotations_variable_c.i diff --git a/CHANGES.current b/CHANGES.current index ae12d1a2c..a715b7e5d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,37 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-03-02: geographika, wsfulton + [Python] #1951 Add Python variable annotations support. + + Both function annotations and variable annotations are turned on using the + "python:annotations" feature. Example: + + %feature("python:annotations", "c"); + + struct V { + float val; + }; + + The generated code contains a variable annotation containing the C float type: + + class V(object): + val: "float" = property(_example.V_val_get, _example.V_val_set) + ... + + Python 3.5 and earlier do not support variable annotations, so variable + annotations can be turned off with a "python:annotations:novar" feature flag. + Example turning on function annotations but not variable annotations globally: + + %feature("python:annotations", "c"); + %feature("python:annotations:novar"); + + or via the command line: + + -features python:annotations=c,python:annotations:novar + + *** POTENTIAL INCOMPATIBILITY *** + 2022-03-02: olly #891 Give error for typemap argument without a value. Previously SWIG segfaulted. @@ -23,6 +54,8 @@ Version 4.1.0 (in progress) -features python:annotations=c + Also see entry dated 2022-03-02, regarding variable annotations. + *** POTENTIAL INCOMPATIBILITY *** 2022-02-26: wsfulton diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 56049ba6c..07cd1e723 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1478,7 +1478,7 @@
  • Python 3 Support
  • Python 3 Support