Skip to content

Commit 4ec675f

Browse files
committed
Minor touchups to code style
1 parent 424f203 commit 4ec675f

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

lib/pyld/jsonld.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def normalize(self, input_, options):
901901
options.setdefault('extractAllScripts', True)
902902
options.setdefault('processingMode', 'json-ld-1.1')
903903

904-
if not options['algorithm'] in ['URDNA2015', 'URGNA2012']:
904+
if options['algorithm'] not in ['URDNA2015', 'URGNA2012']:
905905
raise JsonLdError(
906906
'Unsupported normalization algorithm.',
907907
'jsonld.NormalizeError')
@@ -964,9 +964,9 @@ def from_rdf(self, dataset, options):
964964
if 'format' in options:
965965
# supported formats (processor-specific and global)
966966
if ((self.rdf_parsers is not None and
967-
not options['format'] in self.rdf_parsers) or
967+
options['format'] not in self.rdf_parsers) or
968968
(self.rdf_parsers is None and
969-
not options['format'] in _rdf_parsers)):
969+
options['format'] not in _rdf_parsers)):
970970
raise JsonLdError(
971971
'Unknown input format.',
972972
'jsonld.UnknownFormat', {'format': options['format']})
@@ -1251,10 +1251,8 @@ def compare_values(v1, v2):
12511251
"""
12521252
# 1. equal primitives
12531253
if not _is_object(v1) and not _is_object(v2) and v1 == v2:
1254-
type1 = type(v1)
1255-
type2 = type(v2)
1256-
if type1 == bool or type2 == bool:
1257-
return type1 == type2
1254+
if isinstance(v1, bool) or isinstance(v2, bool):
1255+
return type(v1) is type(v2)
12581256
return True
12591257

12601258
# 2. equal @values
@@ -1263,10 +1261,9 @@ def compare_values(v1, v2):
12631261
v1.get('@type') == v2.get('@type') and
12641262
v1.get('@language') == v2.get('@language') and
12651263
v1.get('@index') == v2.get('@index')):
1266-
type1 = type(v1['@value'])
1267-
type2 = type(v2['@value'])
1268-
if type1 == bool or type2 == bool:
1269-
return type1 == type2
1264+
1265+
if isinstance(v1['@value'], bool) or isinstance(v2['@value'], bool):
1266+
return type(v1['@value']) is type(v2['@value'])
12701267
return True
12711268

12721269
# 3. equal @ids
@@ -2830,7 +2827,6 @@ def _process_context(self, active_ctx, local_ctx, options,
28302827
28312828
:return: the new active context.
28322829
"""
2833-
has_related = 'related' in active_ctx['mappings']
28342830
# normalize local context to an array
28352831
if _is_object(local_ctx) and _is_array(local_ctx.get('@context')):
28362832
local_ctx = local_ctx['@context']
@@ -3062,7 +3058,7 @@ def _process_context(self, active_ctx, local_ctx, options,
30623058
'json-ld-1.0',
30633059
'jsonld.SyntaxError', {'context': ctx},
30643060
code='invalid context entry')
3065-
if type(value) != bool:
3061+
if not isinstance(value, bool):
30663062
raise JsonLdError(
30673063
'Invalid JSON-LD syntax; @propagate value must be a boolean.',
30683064
'jsonld.SyntaxError', {'context': ctx},
@@ -3106,7 +3102,7 @@ def _process_context(self, active_ctx, local_ctx, options,
31063102
raise JsonLdError(
31073103
'Invalid JSON-LD syntax; invalid scoped context.',
31083104
'jsonld.SyntaxError', {'context': key_ctx, 'term': k},
3109-
code='invalid scoped context')
3105+
code='invalid scoped context', cause=cause)
31103106

31113107
# cache processed result (only Python >= 3.6)
31123108
# and give the context a unique identifier
@@ -3772,7 +3768,7 @@ def _match_frame(self, state, subjects, frame, parent, property):
37723768
# when the property is None, which only occurs at the top-level.
37733769
if property is None:
37743770
state['uniqueEmbeds'] = {state['graph']: {}}
3775-
elif not state['graph'] in state['uniqueEmbeds']:
3771+
elif state['graph'] not in state['uniqueEmbeds']:
37763772
state['uniqueEmbeds'][state['graph']] = {}
37773773

37783774
if flags['embed'] == '@link' and id_ in link:
@@ -3847,9 +3843,7 @@ def _match_frame(self, state, subjects, frame, parent, property):
38473843
recurse = state['graph'] != '@merged'
38483844
subframe = {}
38493845
else:
3850-
subframe = frame['@graph'][0]
3851-
if not _is_object(subframe):
3852-
subFrame = {}
3846+
subframe = frame['@graph'][0] if not _is_object(subframe) else {}
38533847
recurse = not (id_ == '@merged' or id_ == '@default')
38543848

38553849
if recurse:
@@ -5126,7 +5120,7 @@ def _create_term_definition(self, active_ctx, local_ctx, term, defined, options,
51265120
mapping['@container'] = container
51275121

51285122
if '@index' in value:
5129-
if not '@container' in value or not '@index' in mapping['@container']:
5123+
if '@container' not in value or '@index' not in mapping['@container']:
51305124
raise JsonLdError(
51315125
'Invalid JSON-LD syntax; @index without @index in @container.',
51325126
'jsonld.SyntaxError',

0 commit comments

Comments
 (0)