You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@hamilton.apache.org by "jernejfrank (via GitHub)" <gi...@apache.org> on 2026/06/08 08:30:58 UTC
Re: [PR] Add Driver helpers for variable lookup [hamilton]
jernejfrank commented on code in PR #1605:
URL: https://github.com/apache/hamilton/pull/1605#discussion_r3371733605
##########
hamilton/driver.py:
##########
@@ -792,6 +793,26 @@ def list_available_variables(
results = [Variable.from_node(n) for n in all_nodes]
return results
+ @functools.cached_property
Review Comment:
Any particular reason for this to be cached? IMO, if the cache is required, would be better to have this as an internal variable explicitly instead of introducing hidden state
##########
hamilton/driver.py:
##########
@@ -792,6 +793,26 @@ def list_available_variables(
results = [Variable.from_node(n) for n in all_nodes]
return results
+ @functools.cached_property
+ def variables(self) -> dict[str, Variable]:
+ """Returns all variables in the graph keyed by name."""
+ return {
+ node_name: Variable.from_node(node_) for node_name, node_ in self.graph.nodes.items()
+ }
Review Comment:
On second thought, if we are exposing `get_graph`, that should already give us the names of the nodes and combining it with `get_variable` makes the API consistent and cleaner. So maybe we remove `variables` for now and can always add it in case it is really desired.
##########
hamilton/driver.py:
##########
@@ -792,6 +793,26 @@ def list_available_variables(
results = [Variable.from_node(n) for n in all_nodes]
return results
+ @functools.cached_property
+ def variables(self) -> dict[str, Variable]:
+ """Returns all variables in the graph keyed by name."""
+ return {
+ node_name: Variable.from_node(node_) for node_name, node_ in self.graph.nodes.items()
+ }
+
+ def get_variable(self, name: str) -> Variable:
+ """Returns a variable by name.
+
+ :param name: Name of the variable to return.
+ :return: Matching HamiltonNode.
+ :raises KeyError: If the variable does not exist in this Driver's graph.
+ """
+ return self.variables[name]
Review Comment:
We could do build this straight from `self.graph` so it still retains the hashmap lookup speed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@hamilton.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org