refactor tpye check
This commit is contained in:
@@ -400,6 +400,11 @@ class ReplaceOperation(PatchOperation):
|
|||||||
value = self.operation["value"]
|
value = self.operation["value"]
|
||||||
subobj, part = self.pointer.to_last(obj)
|
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(doc),)
|
||||||
|
|
||||||
if part is None:
|
if part is None:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@@ -412,10 +417,6 @@ class ReplaceOperation(PatchOperation):
|
|||||||
raise JsonPatchConflict("can't replace non-existant object '%s'"
|
raise JsonPatchConflict("can't replace non-existant object '%s'"
|
||||||
"" % part)
|
"" % part)
|
||||||
|
|
||||||
else:
|
|
||||||
raise JsonPatchConflict("can't replace in type '%s'"
|
|
||||||
"" % subobj.__class__.__name__)
|
|
||||||
|
|
||||||
subobj[part] = value
|
subobj[part] = value
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user