diff --git a/CHANGES.current b/CHANGES.current index 2563749a2..1dc7709da 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,20 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.1.0 (in progress) =========================== +2022-02-27: wsfulton + [Python] #735 #1561 Function annotations containing C/C++ types are no longer + generated when using the -py3 option. Function annotations support has been + moved to a feature to provide finer grained control. It can be turned on + globally by adding: + + %feature("python:annotations", "c"); + + or by using the command line argument: + + -features python:annotations=c + + *** POTENTIAL INCOMPATIBILITY *** + 2022-02-26: wsfulton #655 #1840 Add new warning WARN_LANG_USING_NAME_DIFFERENT to warn when a method introduced by a using declaration in a derived class cannot diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index b1da2953a..433ae5f9e 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -1478,7 +1478,10 @@
-The -py3 option will enable function annotation support. When used -SWIG is able to generate proxy method definitions like this: -
- -- def foo(self, bar : "int"=0) -> "void" : ... -
-Also, even if without passing SWIG the -py3 option, the parameter list -still could be generated: -
- -- def foo(self, bar=0): ... -
-But for overloaded function or method, the parameter list would fallback to -*args or self, *args, and **kwargs may be append -depend on whether you enabled the keyword argument. This fallback is due to -all overloaded functions share the same function in SWIG generated proxy class. -
- --For detailed usage of function annotation, see +Python 3 supports function annotations as defined in PEP 3107. +Annotation support is via a python:annotations +%feature directives. +SWIG currently supports one type of function annotation. +
+ ++The %feature("python:annotations", "c") directive generates function annotations +containing C/C++ types. For example: +
+ +
+%feature("python:annotations", "c") global_ints;
+int *global_ints(int &ri);
++The generated code then contains function annotations containing the C types: +
+ ++def global_ints(ri: "int &") -> "int *": + return _python_annotations_c.global_ints(ri) +
+There are some limitations with annotations support, for example, overloaded functions use +*args or **kwargs when keyword arguments are enabled. +The parameter names and types are then not shown. For example, with input: +
+ ++int *global_overloaded(int &ri); +int *global_overloaded(); +
+The generated Python function including annotations is shown below. +Only the return type is annotated. +
+ ++def global_overloaded(*args) -> "int *": + return _python_annotations_c.global_overloaded(*args) +
+Compatibility Note: SWIG-4.1.0 changed the way that function annotations are generated. +Prior versions required the -py3 option which enabled function annotation support +containing C/C++ types instead of supporting %feature("python:annotations", "c").