Skip to content

Remove assert statements from code base #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions redisgraph/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ def __init__(self, src_node, relation, dest_node, edge_id=None, properties=None)
"""
Create a new edge.
"""
assert src_node is not None and dest_node is not None
if not (src_node and dest_node):
# NOTE(bors-42): It makes sense to change AssertionError to
# ValueError here
raise AssertionError("Both src_node & dest_node must be provided")

self.id = edge_id
self.relation = '' or relation
self.properties = {} or properties
self.relation = relation or ''
self.properties = properties or {}
self.src_node = src_node
self.dest_node = dest_node

Expand Down
13 changes: 7 additions & 6 deletions redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def add_node(self, node):

def add_edge(self, edge):
"""
Addes an edge to the graph.
Adds an edge to the graph.
"""
if not (self.nodes[edge.src_node.alias]
and self.nodes[edge.dest_node.alias]):
raise AssertionError("Both edge's end must be in the graph")

# Make sure edge both ends are in the graph
assert self.nodes[edge.src_node.alias] is not None and self.nodes[edge.dest_node.alias] is not None
self.edges.append(edge)

def commit(self):
Expand Down Expand Up @@ -128,12 +129,13 @@ def flush(self):
self.edges = []

def build_params_header(self, params):
assert type(params) == dict
if not isinstance(params, dict):
raise TypeError("'params' must be a dict")
# Header starts with "CYPHER"
params_header = "CYPHER "
for key, value in params.items():
# If value is string add quotation marks.
if type(value) == str:
if isinstance(value, str):
value = quote_string(value)
# Value is None, replace with "null" string.
elif value is None:
Expand Down Expand Up @@ -189,7 +191,6 @@ def execution_plan(self, query, params=None):
Get the execution plan for given query,
GRAPH.EXPLAIN returns an array of operations.
"""

if params is not None:
query = self.build_params_header(params) + query

Expand Down