Add Python < 3.3 support for pyabc.i

pyabc.i for abstract base classes now supports versions of Python
prior to 3.3 by using the collection module for these older versions.
Python-3.3 and later continue to use the collections.abc module.
The -py3 option no longer has any effect on the %pythonabc feature.
This commit is contained in:
William S Fulton 2022-03-21 23:56:54 +00:00
commit f068f2c2d6
6 changed files with 51 additions and 36 deletions

View file

@ -1,10 +1,14 @@
%define %pythonabc(Type, Abc)
%feature("python:abc", #Abc) Type;
%feature("python:abc", Abc) Type;
%enddef
%pythoncode %{import collections.abc%}
%pythonabc(std::vector, collections.abc.MutableSequence);
%pythonabc(std::list, collections.abc.MutableSequence);
%pythonabc(std::map, collections.abc.MutableMapping);
%pythonabc(std::multimap, collections.abc.MutableMapping);
%pythonabc(std::set, collections.abc.MutableSet);
%pythonabc(std::multiset, collections.abc.MutableSet);
%pythoncode %{if _swig_python_version_info[0:2] >= (3, 3):
import collections.abc
else:
import collections
%}
%pythonabc(std::vector, "collections.abc.MutableSequence if _swig_python_version_info >= (3, 3) else collections.MutableSequence");
%pythonabc(std::list, "collections.abc.MutableSequence if _swig_python_version_info >= (3, 3) else collections.MutableSequence");
%pythonabc(std::map, "collections.abc.MutableMapping if _swig_python_version_info >= (3, 3) else collections.MutableMapping");
%pythonabc(std::multimap, "collections.abc.MutableMapping if _swig_python_version_info >= (3, 3) else collections.MutableMapping");
%pythonabc(std::set, "collections.abc.MutableSet if _swig_python_version_info >= (3, 3) else collections.MutableSet");
%pythonabc(std::multiset, "collections.abc.MutableSet if _swig_python_version_info >= (3, 3) else collections.MutableSet");