@@ -417,13 +417,7 @@ def apply(self, obj):
417
417
value = self .operation ["value" ]
418
418
subobj , part = self .pointer .to_last (obj )
419
419
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
-
425
420
if isinstance (subobj , list ):
426
-
427
421
if part == '-' :
428
422
subobj .append (value ) # pylint: disable=E1103
429
423
@@ -439,6 +433,9 @@ def apply(self, obj):
439
433
else :
440
434
subobj [part ] = value
441
435
436
+ else :
437
+ raise TypeError ("invalid document type %s" % (type (subobj ),))
438
+
442
439
return obj
443
440
444
441
@@ -449,11 +446,6 @@ def apply(self, obj):
449
446
value = self .operation ["value" ]
450
447
subobj , part = self .pointer .to_last (obj )
451
448
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
-
457
449
if part is None :
458
450
return value
459
451
@@ -466,6 +458,9 @@ def apply(self, obj):
466
458
raise JsonPatchConflict ("can't replace non-existent object '%s'"
467
459
% part )
468
460
461
+ else :
462
+ raise TypeError ("invalid document type %s" % (type (subobj ),))
463
+
469
464
subobj [part ] = value
470
465
return obj
471
466
0 commit comments