diff options
author | Serge Guelton <sguelton@quarkslab.com> | 2019-01-05 12:07:36 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@quarkslab.com> | 2019-01-05 12:07:36 +0000 |
commit | f098e402487681b6d371d8a5c731b320412d8435 (patch) | |
tree | 1220eedd2f553a2ead1f80d81e7d27c9291c90b7 /bindings | |
parent | 0da4016acab85eaae8b07d807cfcf35028d6e4d0 (diff) | |
download | clang-f098e402487681b6d371d8a5c731b320412d8435.tar.gz |
[python] Make the collections import future-proof
On Python 3.7 the old code raises a warning:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
class ArgumentsIterator(collections.Sequence):
On Python 3.8 it wouldn't work anymore.
Commited on behalf of Jakub Stasiak.
Differential Revision: https://reviews.llvm.org/D56341
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350467 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/clang/cindex.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 54514b8dae..8b23ae90b9 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -64,7 +64,6 @@ from __future__ import absolute_import, division, print_function # o implement additional SourceLocation, SourceRange, and File methods. from ctypes import * -import collections import clang.enumerations @@ -123,6 +122,14 @@ elif sys.version_info[0] == 2: def b(x): return x +# Importing ABC-s directly from collections is deprecated since Python 3.7, +# will stop working in Python 3.8. +# See: https://docs.python.org/dev/whatsnew/3.7.html#id3 +if sys.version_info[:2] >= (3, 7): + from collections import abc as collections_abc +else: + import collections as collections_abc + # We only support PathLike objects on Python version with os.fspath present # to be consistent with the Python standard library. On older Python versions # we only support strings and we have dummy fspath to just pass them through. @@ -2181,7 +2188,7 @@ class Type(Structure): The returned object is iterable and indexable. Each item in the container is a Type instance. """ - class ArgumentsIterator(collections.Sequence): + class ArgumentsIterator(collections_abc.Sequence): def __init__(self, parent): self.parent = parent self.length = None |