Python function annotations removed from -py3 option.

Python 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

The implementation is designed to be expandable to support different
annotations implementations. Future implementations could implement
something like the following for generating pure Python types:

  %feature("python:annotations", "python");

or typing module types to conform to PEP-484:

  %feature("python:annotations", "typing");

Closes #1561
Issue #735
This commit is contained in:
William S Fulton 2022-02-27 10:06:45 +00:00
commit 2072ae19c9
7 changed files with 133 additions and 33 deletions

View file

@ -0,0 +1,26 @@
%module python_annotations_c
// Tests the C/C++ annotations that were automatically added by using -py3 before swig-4.1.0
// In swig-4.1.0 and later, the feature below is needed as annotations are no longer generated with -py3
%feature("python:annotations", "c") mymethod;
%feature("python:annotations", "c") makeT<short>;
%feature("python:annotations", "c") global_ints;
%inline %{
namespace Space {
template<class T>
struct Template {
void mymethod(int, Template* tt) {}
};
}
template<typename T>
Space::Template<T> makeT(int x) {
return Space::Template<T>();
};
int *global_ints(int &ri, Space::Template<short> t) { return &ri; }
int *global_overloaded(int &ri) { return &ri; }
int *global_overloaded() { return NULL; }
int *no_annotations(int &ri, const char *c) { return NULL; }
%}
%template(TemplateShort) Space::Template<short>;
%template(MakeShort) makeT<short>;