bindings: try importing collections.abc first for forward compatibility
authorChristophe Bedard <bedard.christophe@gmail.com>
Sat, 25 Apr 2020 02:54:45 +0000 (22:54 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 7 May 2020 16:21:43 +0000 (12:21 -0400)
Using the babeltrace Python module with Python 3.3-3.8 gives a warning:

/usr/lib/python3/dist-packages/babeltrace/babeltrace.py:811:
DeprecationWarning: Using or importing the ABCs from 'collections'
instead of from 'collections.abc' is deprecated since Python 3.3,
and in 3.9 it will stop working

Therefore, for forward compability (Python 3.9+), try importing it
using the new way first. Otherwise, fall back on the old way.

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
Change-Id: I7f650593a013643b2fb0b77b0d388cf57bc2b765
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/babeltrace/babeltrace.i.in

index a773e9b37379899dbf597117976f774221c126de..8eec1c1d1e7864ea1a6aa21063d0b50a90fb1aed 100644 (file)
@@ -672,8 +672,11 @@ class CTFScope:
 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
        CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
 
 _scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
        CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
 
-import collections
-class Event(collections.Mapping):
+try:
+       import collections.abc as collections_abc
+except ImportError:
+       import collections as collections_abc  # Fallback for Python 3.2
+class Event(collections_abc.Mapping):
        """
        This class represents an event from the trace.
        It is obtained using the TraceCollection generator functions.
        """
        This class represents an event from the trace.
        It is obtained using the TraceCollection generator functions.
This page took 0.02679 seconds and 4 git commands to generate.