Handle collections.abc deprecations

The use of ABC classes directly from collections has been deprecated in
3.x versions of Python. The direction is to use the classes defined in
collections.abc. Python 2.7 does not have this, but Python 3.8 will be
dropping the backwards compatibility to use the old location.

Six also does not have support for this yet, so in the mean time to make
sure we don't run into issues as folks try to move to 3.8, and to get
rid of deprecation warnings in logs, this handles importing from the
preferred location and falls back if it not available.

Change-Id: I15554bf3c109045ebdc237ce7cb40299f5d1b298
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2019-04-03 11:00:18 -05:00 committed by Stephen Finucane
parent 09459070fd
commit 23889f5616

View File

@ -15,6 +15,16 @@
# under the License.
import collections
# TODO(smcginnis) update this once six has support for collections.abc
# (https://github.com/benjaminp/six/pull/241) or clean up once we drop py2.7.
try:
from collections.abc import Hashable
from collections.abc import Set
except ImportError:
from collections import Hashable
from collections import Set
import itertools
import six
@ -32,7 +42,7 @@ def _merge_in(target, iterable=None, sentinel=_sentinel):
return target
class OrderedSet(collections.Set, collections.Hashable):
class OrderedSet(Set, Hashable):
"""A read-only hashable set that retains insertion/initial ordering.
It should work in all existing places that ``frozenset`` is used.