Skip to content

Commit ff0fadf

Browse files
committed
Use ABCs instead of list/dict
see stefankoegl/python-json-patch#33
1 parent 7c4a5fc commit ff0fadf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

jsonpointer.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
""" Identify specific nodes in a JSON document (RFC 6901) """
3636

37+
try:
38+
from collections.abc import Mapping, Sequence
39+
except ImportError:
40+
from collections import Mapping, Sequence
41+
3742
# Will be parsed by setup.py to determine package metadata
3843
__author__ = 'Stefan Kögl <[email protected]>'
3944
__version__ = '1.4'
@@ -191,10 +196,10 @@ def set(self, doc, value, inplace=True):
191196
def get_part(self, doc, part):
192197
""" Returns the next step in the correct type """
193198

194-
if isinstance(doc, dict):
199+
if isinstance(doc, Mapping):
195200
return part
196201

197-
elif isinstance(doc, list):
202+
elif isinstance(doc, Sequence):
198203

199204
if part == '-':
200205
return part
@@ -220,14 +225,14 @@ def walk(self, doc, part):
220225

221226
assert (type(doc) in (dict, list) or hasattr(doc, '__getitem__')), "invalid document type %s" % (type(doc),)
222227

223-
if isinstance(doc, dict):
228+
if isinstance(doc, Mapping):
224229
try:
225230
return doc[part]
226231

227232
except KeyError:
228233
raise JsonPointerException("member '%s' not found in %s" % (part, doc))
229234

230-
elif isinstance(doc, list):
235+
elif isinstance(doc, Sequence):
231236

232237
if part == '-':
233238
return EndOfList(doc)

0 commit comments

Comments
 (0)