From 64b7b73406242324460e4df149eff329b289192a Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Fri, 24 Apr 2020 22:54:45 -0400 Subject: [PATCH] bindings: try importing collections.abc first for forward compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Change-Id: I7f650593a013643b2fb0b77b0d388cf57bc2b765 Signed-off-by: Jérémie Galarneau --- bindings/python/babeltrace/babeltrace.i.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bindings/python/babeltrace/babeltrace.i.in b/bindings/python/babeltrace/babeltrace.i.in index a773e9b3..8eec1c1d 100644 --- a/bindings/python/babeltrace/babeltrace.i.in +++ b/bindings/python/babeltrace/babeltrace.i.in @@ -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] -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. -- 2.34.1