Skip to content

Commit fe92912

Browse files
committed
update_jsonld: do not modify the caller's dict
1 parent 6454fd2 commit fe92912

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

rocrate/rocrate.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,7 @@ def update_jsonld(self, jsonld):
558558
entity: Entity = self.get(entity_id)
559559
if not entity:
560560
raise ValueError(f"entity {entity_id} does not exist in the RO-Crate")
561-
# Keys starting with @ are removed here to avoid messing up things.
562-
# https://github.com/ResearchObject/ro-crate-py/pull/149#issuecomment-1487039274
563-
for key in list(jsonld.keys()):
564-
if key.startswith('@'):
565-
del jsonld[key]
561+
jsonld = {k: v for k, v in jsonld.items() if not k.startswith('@')}
566562
entity._jsonld.update(jsonld)
567563
return entity
568564

test/test_jsonld.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ def test_update_jsonld(test_data_dir):
157157
assert updated_entity.type == 'CreativeWork'
158158
assert updated_entity['name'] == 'No potatoes today'
159159

160+
assert '@type' in update_dict
161+
160162

161163
# --- add or update
162164

0 commit comments

Comments
 (0)