Skip to content

Commit

Permalink
fix zn.nodes(None) (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ authored Mar 21, 2023
1 parent 4d84471 commit 6226c73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/integration/test_none_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ def test_from_dvc_deps(proj_path, eager):

class EmptyNodesNode(zntrack.Node):
nodes = zntrack.zn.nodes(None)
outs = zntrack.zn.outs()

def run(self):
pass
self.outs = 42


def test_EmptyNode(proj_path):
@pytest.mark.parametrize("eager", [True, False])
def test_EmptyNode(proj_path, eager):
with zntrack.Project() as project:
node = EmptyNodesNode()
project.run(eager=eager)
if not eager:
node.load()
assert node.outs == 42
2 changes: 2 additions & 0 deletions zntrack/fields/zn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ def __set__(self, instance, value):
def get_node_names(self, instance) -> list:
"""Get the name of the other Node."""
value = instance.__dict__[self.name]
if value is None: # the zn.nodes(None) case
return []
if isinstance(value, (list, tuple)):
return [f"{instance.name}_{self.name}_{idx}" for idx in range(len(value))]
return [f"{instance.name}_{self.name}"]
Expand Down

0 comments on commit 6226c73

Please sign in to comment.