Skip to content
Snippets Groups Projects
Commit 3af1c01a authored by Radko Krkoš's avatar Radko Krkoš
Browse files

jpath: Use `x not in y` instead of `not x in y`

parent 36a6055b
Branches
No related tags found
No related merge requests found
......@@ -242,7 +242,7 @@ def jpath_parse_c(jpath):
references to internal cache. Treat the returned values as read only, or
suffer the consequences.
"""
if not jpath in _JPATH_CACHE:
if jpath not in _JPATH_CACHE:
_JPATH_CACHE[jpath] = jpath_parse(jpath)
return _JPATH_CACHE[jpath]
......@@ -294,7 +294,7 @@ def jpath_values(structure, jpath):
# Process unindexed nodes.
else:
# Skip the node, if the key does not exist.
if not key in node:
if key not in node:
continue
# Handle list values - expand them.
......@@ -338,7 +338,7 @@ def jpath_exists(structure, jpath):
:rtype: bool
"""
result = jpath_value(structure, jpath)
if not result is None:
if result is not None:
return True
return False
......@@ -375,7 +375,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
idx = chnk['i']
# Automatically create nodes for non-existent keys.
if not key in current:
if key not in current:
current[key] = []
if not isinstance(current[key], list) and not isinstance(current[key], MutableSequence):
raise JPathException("Expected list-like object under structure key '{}'".format(key))
......@@ -412,7 +412,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
except (IndexError, TypeError):
# At this point only deal with unique, overwrite does not make
# sense, because we would not be here otherwise.
if not unique or not value in current[key]:
if not unique or value not in current[key]:
current[key].append(value)
else:
return RC_VALUE_DUPLICATE
......@@ -422,7 +422,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
# Detection of the last JPath chunk - node somewhere in the middle.
if i != size:
# Automatically create nodes for non-existent keys.
if not key in current:
if key not in current:
current[key] = {}
if not isinstance(current[key], dict) and not isinstance(current[key], Mapping):
raise JPathException("Expected dict-like object under structure key '{}'".format(key))
......@@ -431,7 +431,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
# Detection of the last JPath chunk - node at the end.
else:
if overwrite or not key in current:
if overwrite or key not in current:
current[key] = value
else:
return RC_VALUE_EXISTS
......@@ -471,7 +471,7 @@ def jpath_unset(structure, jpath):
idx = chnk['i']
# Skip nodes for non-existent keys.
if not key in node:
if key not in node:
continue
if not isinstance(node[key], list) and not isinstance(node[key], MutableSequence):
raise JPathException("Expected list-like object under structure key '{}'".format(key))
......@@ -507,7 +507,7 @@ def jpath_unset(structure, jpath):
# Detection of the last JPath chunk - node somewhere in the middle.
if i != size:
# Skip nodes for non-existent keys.
if not key in node:
if key not in node:
continue
if isinstance(node[key], list):
nodes_b.extend(node[key])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment