summaryrefslogtreecommitdiff
path: root/Lib/python
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-03-21 23:56:54 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-03-23 07:58:01 +0000
commitf068f2c2d6d2d8f8a3c101f34fc290d3b822653e (patch)
treeec5496bfdd37cf3e55b5f278d1617312652b69b3 /Lib/python
parent9fd23561040de88f4e8e88bc3515f6fa2739f6e4 (diff)
downloadswig-f068f2c2d6d2d8f8a3c101f34fc290d3b822653e.tar.gz
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.
Diffstat (limited to 'Lib/python')
-rw-r--r--Lib/python/pyabc.i20
1 files changed, 12 insertions, 8 deletions
diff --git a/Lib/python/pyabc.i b/Lib/python/pyabc.i
index fbd91dce4..cae1e7032 100644
--- a/Lib/python/pyabc.i
+++ b/Lib/python/pyabc.i
@@ -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");