From: Scott Johnson Date: Sat, 22 Jun 2019 12:16:23 +0000 (-0700) Subject: Fix deprecation warning in Python 3.7 (#231) X-Git-Tag: v0.26~18 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=923c498fd2c3c9805c613f8ac33e5572b9a784e2;p=pyelftools.git Fix deprecation warning in Python 3.7 (#231) $SITE_PYTHON/lib/python3.7/site-packages/elftools/construct/lib/container.py:5 Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working This change is compatible with Python 3.3 and up, when the ABCs were moved to collections.abc. Backward compatibility is retained through the try/except block. --- diff --git a/elftools/construct/lib/container.py b/elftools/construct/lib/container.py index 2f89b2d..5a580fa 100644 --- a/elftools/construct/lib/container.py +++ b/elftools/construct/lib/container.py @@ -2,8 +2,8 @@ Various containers. """ -from collections import MutableMapping from pprint import pformat +from .py3compat import MutableMapping def recursion_lock(retval, lock_name = "__recursion_lock__"): def decorator(func): diff --git a/elftools/construct/lib/py3compat.py b/elftools/construct/lib/py3compat.py index 4a52c29..1cbae81 100644 --- a/elftools/construct/lib/py3compat.py +++ b/elftools/construct/lib/py3compat.py @@ -6,6 +6,11 @@ import sys PY3 = sys.version_info[0] == 3 +try: + from collections.abc import MutableMapping # python >= 3.3 +except ImportError: + from collections import MutableMapping # python < 3.3 + if PY3: import io