From: Christophe Bedard Date: Sat, 25 Apr 2020 02:54:45 +0000 (-0400) Subject: bindings: try importing collections.abc first for forward compatibility X-Git-Tag: v1.5.9~3 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=64b7b73406242324460e4df149eff329b289192a bindings: try importing collections.abc first for forward compatibility 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 --- 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.