diff options
author | Alexander Shorin <kxepal@apache.org> | 2013-11-12 08:19:29 +0400 |
---|---|---|
committer | Alexander Shorin <kxepal@apache.org> | 2013-11-12 08:19:29 +0400 |
commit | 3ab6c5a251110fcf06d3e740e7658fa089c9e1eb (patch) | |
tree | f062da27977d402f16cc697976b46ed35b78455d | |
parent | cbe80b0d7cb8ce12d6f65031a4fab9f9398db701 (diff) | |
download | python-json-patch-3ab6c5a251110fcf06d3e740e7658fa089c9e1eb.tar.gz |
Raise TypeError instead of AssertionError
-rw-r--r-- | jsonpatch.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index e70a85c..0a0aa04 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -417,13 +417,7 @@ class AddOperation(PatchOperation): value = self.operation["value"] subobj, part = self.pointer.to_last(obj) - # type is already checked in to_last(), so we assert here - # for consistency - assert isinstance(subobj, list) or isinstance(subobj, dict), \ - "invalid document type %s" % type(subobj) - if isinstance(subobj, list): - if part == '-': subobj.append(value) # pylint: disable=E1103 @@ -439,6 +433,9 @@ class AddOperation(PatchOperation): else: subobj[part] = value + else: + raise TypeError("invalid document type %s" % (type(subobj),)) + return obj @@ -449,11 +446,6 @@ class ReplaceOperation(PatchOperation): value = self.operation["value"] subobj, part = self.pointer.to_last(obj) - # type is already checked in to_last(), so we assert here - # for consistency - assert isinstance(subobj, list) or isinstance(subobj, dict), \ - "invalid document type %s" % subobj - if part is None: return value @@ -466,6 +458,9 @@ class ReplaceOperation(PatchOperation): raise JsonPatchConflict("can't replace non-existent object '%s'" % part) + else: + raise TypeError("invalid document type %s" % (type(subobj),)) + subobj[part] = value return obj |