aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2018-10-31 09:55:36 -0500
committerGitHub <noreply@github.com>2018-10-31 09:55:36 -0500
commit68064e2e8f60687674071f9c791603b0ae6a76a4 (patch)
tree49105e52d8931388a3a476cc1e88593cf1375436
parente03fe75a0e3bcd55c545e94aa6ced0b4bb689f5a (diff)
parent255c70115059c0d3347f6fbe3776031d4a52d009 (diff)
downloaduritemplates-68064e2e8f60687674071f9c791603b0ae6a76a4.tar.gz
Merge pull request #40 from jwodder/master
Import ABCs from collections.abc if possible
-rw-r--r--uritemplate/orderedset.py8
-rw-r--r--uritemplate/variable.py8
2 files changed, 12 insertions, 4 deletions
diff --git a/uritemplate/orderedset.py b/uritemplate/orderedset.py
index 7a9d33e..f21c9cb 100644
--- a/uritemplate/orderedset.py
+++ b/uritemplate/orderedset.py
@@ -1,14 +1,18 @@
# From: https://github.com/ActiveState/code/blob/master/recipes/Python/576696_OrderedSet_with_Weakrefs/ # noqa
-import collections
from weakref import proxy
+try:
+ import collections.abc as collections_abc
+except ImportError:
+ import collections as collections_abc
+
class Link(object):
__slots__ = 'prev', 'next', 'key', '__weakref__'
-class OrderedSet(collections.MutableSet):
+class OrderedSet(collections_abc.MutableSet):
'Set the remembers the order elements were added'
# Big-O running times for all methods are the same as for regular sets.
# The internal self.__map dictionary maps keys to links in a doubly linked
diff --git a/uritemplate/variable.py b/uritemplate/variable.py
index 0d2e695..a3bd4ce 100644
--- a/uritemplate/variable.py
+++ b/uritemplate/variable.py
@@ -15,9 +15,13 @@ What do you do?
"""
-import collections
import sys
+try:
+ import collections.abc as collections_abc
+except ImportError:
+ import collections as collections_abc
+
if sys.version_info.major == 2:
import urllib
elif sys.version_info.major == 3:
@@ -360,7 +364,7 @@ def list_test(value):
def dict_test(value):
- return isinstance(value, (dict, collections.MutableMapping))
+ return isinstance(value, (dict, collections_abc.MutableMapping))
try: