diff --git a/CHANGES.current b/CHANGES.current index f60516cfc..873f2b402 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,22 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2018-06-12: wsfulton + [Python] The %pythonabc feature in pyabc.i now uses base classes + collections.abc.MutableSequence + collections.abc.MutableMapping + collections.abc.MutableSet + instead of + collections.MutableSequence + collections.MutableMapping + collections.MutableSet + as the latter are deprecated in Python 3.7 and are due to be removed in Python 3.8. + The classes in collections.abc.* are available from Python 3.3 onwards. If you + require support for Python 3.2, then copy the pyabc.i file and modify by removing + the few instances of the .abc sub-module. + + *** POTENTIAL INCOMPATIBILITY *** + 2018-06-12: olly,wsfulton [Python] #701 Remove support for Python versions < 2.7 and 3.0 and 3.1. diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index f3550baf2..799342f6e 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -6426,7 +6426,8 @@ modify the buffer.

By including pyabc.i and using the -py3 command line option when calling SWIG, the proxy classes of the STL containers -will automatically gain an appropriate abstract base class. For +will automatically gain an appropriate abstract base class from the +collections.abc module. For example, the following SWIG interface:

@@ -6443,8 +6444,8 @@ namespace std {

will generate a Python proxy class Mapii inheriting from -collections.MutableMap and a proxy class IntList -inheriting from collections.MutableSequence. +collections.abc.MutableMap and a proxy class IntList +inheriting from collections.abc.MutableSequence.

@@ -6453,7 +6454,7 @@ used to define an abstract base class for your own C++ class:

-%pythonabc(MySet, collections.MutableSet);
+%pythonabc(MySet, collections.abc.MutableSet);
 

@@ -6461,6 +6462,14 @@ For details of abstract base class, please see PEP 3119.

+

+Compatibility Note: SWIG-4.0.0 changed the base classes to use the +collections.abc module instead of collections due to the deprecation +of the classes in the collections module in Python 3.7. +The collections.abc module was introduced in Python 3.3 and hence this feature +requires Python 3.3 or later. +

+

38.12.4 Byte string output conversion

diff --git a/Examples/test-suite/python/python_abstractbase_runme3.py b/Examples/test-suite/python/python_abstractbase_runme3.py index 4fdc79935..9f99dcb54 100644 --- a/Examples/test-suite/python/python_abstractbase_runme3.py +++ b/Examples/test-suite/python/python_abstractbase_runme3.py @@ -1,5 +1,11 @@ +import sys + +# collections.abc requires Python 3.3+ +if sys.version_info[0:2] < (3, 3): + exit(0) + from python_abstractbase import * -from collections import * +import collections.abc # This is expected to fail with -builtin option # Builtin types can't inherit from pure-python abstract bases @@ -10,12 +16,16 @@ if is_python_builtin(): if not is_swig_py3: exit(0) -assert issubclass(Mapii, MutableMapping) -assert issubclass(Multimapii, MutableMapping) -assert issubclass(IntSet, MutableSet) -assert issubclass(IntMultiset, MutableSet) -assert issubclass(IntVector, MutableSequence) -assert issubclass(IntList, MutableSequence) +def check_issubclass(derived, base): + if not issubclass(derived, base): + raise RuntimeError("{} is not a subclass of {}".format(derived, base)) + +check_issubclass(Mapii, collections.abc.MutableMapping) +check_issubclass(Multimapii, collections.abc.MutableMapping) +check_issubclass(IntSet, collections.abc.MutableSet) +check_issubclass(IntMultiset, collections.abc.MutableSet) +check_issubclass(IntVector, collections.abc.MutableSequence) +check_issubclass(IntList, collections.abc.MutableSequence) mapii = Mapii() multimapii = Multimapii() diff --git a/Lib/python/pyabc.i b/Lib/python/pyabc.i index 12ce65985..fbd91dce4 100644 --- a/Lib/python/pyabc.i +++ b/Lib/python/pyabc.i @@ -1,10 +1,10 @@ %define %pythonabc(Type, Abc) %feature("python:abc", #Abc) Type; %enddef -%pythoncode %{import collections%} -%pythonabc(std::vector, collections.MutableSequence); -%pythonabc(std::list, collections.MutableSequence); -%pythonabc(std::map, collections.MutableMapping); -%pythonabc(std::multimap, collections.MutableMapping); -%pythonabc(std::set, collections.MutableSet); -%pythonabc(std::multiset, collections.MutableSet); +%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);