Skip to content

Commit f857e9d

Browse files
committed
type fixups
1 parent 0407370 commit f857e9d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

schema_salad/jsonld_context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ def salad_to_jsonld_context(j, schema_ctx):
177177
return (context, g)
178178

179179
def fix_jsonld_ids(obj, ids):
180+
# type: (Union[Dict[unicode, Any], List[Dict[unicode, Any]]], List[unicode]) -> None
180181
if isinstance(obj, dict):
181182
for i in ids:
182183
if i in obj:
183184
obj["@id"] = obj[i]
184185
for v in obj.values():
185186
fix_jsonld_ids(v, ids)
186187
if isinstance(obj, list):
187-
for i in obj:
188-
fix_jsonld_ids(i, ids)
188+
for entry in obj:
189+
fix_jsonld_ids(entry, ids)
189190

190191
def makerdf(workflow, wf, ctx):
191192
# type: (Union[str, unicode], Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Loader.ContextType) -> Graph

schema_salad/main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def printrdf(workflow, wf, ctx, sr):
26-
# type: (str, Union[List, Dict[Any, Any], str, unicode], Dict[unicode, Any], str) -> None
26+
# type: (str, Union[List[Dict[unicode, Any]], Dict[unicode, Any]], Dict[unicode, Any], str) -> None
2727
g = jsonld_context.makerdf(workflow, wf, ctx)
2828
print(g.serialize(format=sr))
2929

@@ -209,8 +209,12 @@ def main(argsl=None): # type: (List[str]) -> int
209209

210210
# Optionally convert the document to RDF
211211
if args.print_rdf:
212-
printrdf(args.document, document, schema_ctx, args.rdf_serializer)
213-
return 0
212+
if isinstance(document, (dict, list)):
213+
printrdf(args.document, document, schema_ctx, args.rdf_serializer)
214+
return 0
215+
else:
216+
print("Document must be a dictionary or list.")
217+
return 1
214218

215219
if args.print_metadata:
216220
print(json.dumps(doc_metadata, indent=4))

0 commit comments

Comments
 (0)