Skip to content

Commit 0f4b1a9

Browse files
committed
Added pytype None checks to calculate.py
PiperOrigin-RevId: 845226580
1 parent 45f34ab commit 0f4b1a9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

struct2tensor/calculate.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ def __str__(self) -> str:
259259

260260
def _create_value_error(self) -> ValueError:
261261
"""Creates a ValueError, assuming there should be one for this node."""
262+
assert self.value is not None
262263
return ValueError("Expression {} returned the wrong type:"
263264
" expected: {}"
264265
" actual: {}.".format(
@@ -353,8 +354,14 @@ def calculate_values(
353354
options: calculate_options.Options,
354355
feed_dict: Optional[Dict[expression.Expression, prensor.Prensor]] = None
355356
) -> None:
357+
"""Calculates the values of the expressions in the graph."""
356358
for node in self.ordered_node_list:
357-
source_values = [self._node[id(x)].value for x in node.sources]
359+
source_values = [
360+
self._node[id(x)].value
361+
for x in node.sources
362+
if self._node[id(x)] is not None
363+
and self._node[id(x)].value is not None
364+
]
358365
side_info = feed_dict[node.expression] if feed_dict and (
359366
node.expression in feed_dict) else None
360367
node.calculate(source_values, options, side_info=side_info)

0 commit comments

Comments
 (0)