Skip to content

Commit

Permalink
check isinstance(options['link'], dict)
Browse files Browse the repository at this point in the history
An empty dict is not truthy in python, so cannot just check
for "if options['link']"

Fixes #64
  • Loading branch information
bpow committed Oct 19, 2017
1 parent 99aca07 commit 878af52
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/pyld/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def compact(self, input_, ctx, options):
options.setdefault('activeCtx', False)
options.setdefault('documentLoader', _default_document_loader)
options.setdefault('link', False)
if options['link']:
if isinstance(options['link'], dict):
# force skip expansion when linking, "link" is not part of the
# public API, it should only be called from framing
options['skipExpansion'] = True
Expand Down Expand Up @@ -1752,7 +1752,7 @@ def _compact(self, active_ctx, active_property, element, options):
if _is_value(element) or _is_subject_reference(element):
rval = self._compact_value(
active_ctx, active_property, element)
if options['link'] and _is_subject_reference(element):
if isinstance(options['link'], dict) and _is_subject_reference(element):
# store linked element
options['link'].setdefault(element['@id'], []).append(
{'expanded': element, 'compacted': rval})
Expand All @@ -1763,7 +1763,7 @@ def _compact(self, active_ctx, active_property, element, options):

rval = {}

if options['link'] and '@id' in element:
if isinstance(options['link'], dict) and '@id' in element:
# store linked element
options['link'].setdefault(element['@id'], []).append(
{'expanded': element, 'compacted': rval})
Expand Down

0 comments on commit 878af52

Please sign in to comment.