Skip to content

Commit 3ab6c5a

Browse files
committed
Raise TypeError instead of AssertionError
1 parent cbe80b0 commit 3ab6c5a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

jsonpatch.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,7 @@ def apply(self, obj):
417417
value = self.operation["value"]
418418
subobj, part = self.pointer.to_last(obj)
419419

420-
# type is already checked in to_last(), so we assert here
421-
# for consistency
422-
assert isinstance(subobj, list) or isinstance(subobj, dict), \
423-
"invalid document type %s" % type(subobj)
424-
425420
if isinstance(subobj, list):
426-
427421
if part == '-':
428422
subobj.append(value) # pylint: disable=E1103
429423

@@ -439,6 +433,9 @@ def apply(self, obj):
439433
else:
440434
subobj[part] = value
441435

436+
else:
437+
raise TypeError("invalid document type %s" % (type(subobj),))
438+
442439
return obj
443440

444441

@@ -449,11 +446,6 @@ def apply(self, obj):
449446
value = self.operation["value"]
450447
subobj, part = self.pointer.to_last(obj)
451448

452-
# type is already checked in to_last(), so we assert here
453-
# for consistency
454-
assert isinstance(subobj, list) or isinstance(subobj, dict), \
455-
"invalid document type %s" % subobj
456-
457449
if part is None:
458450
return value
459451

@@ -466,6 +458,9 @@ def apply(self, obj):
466458
raise JsonPatchConflict("can't replace non-existent object '%s'"
467459
% part)
468460

461+
else:
462+
raise TypeError("invalid document type %s" % (type(subobj),))
463+
469464
subobj[part] = value
470465
return obj
471466

0 commit comments

Comments
 (0)