Skip to content

Commit b72807f

Browse files
committed
Do not require .value for Node.
1 parent 449635e commit b72807f

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/_pytask/node_protocols.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ def state(self) -> str | None:
2929
class Node(MetaNode, Protocol):
3030
"""Protocol for nodes."""
3131

32-
value: Any
33-
3432
def load(self) -> Any:
3533
"""Return the value of the node that will be injected into the task."""
3634
...

src/_pytask/nodes.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,16 @@ class PathNode(Node):
106106

107107
name: str = ""
108108
"""Name of the node which makes it identifiable in the DAG."""
109-
value: Path | None = None
110-
"""Value passed to the decorator which can be requested inside the function."""
111-
112-
@property
113-
def path(self) -> Path:
114-
return self.value
109+
path: Path | None = None
110+
"""The path to the file."""
115111

116112
def from_annot(self, value: Path) -> None:
117113
"""Set path and if other attributes are not set, set sensible defaults."""
118114
if not isinstance(value, Path):
119115
raise TypeError("'value' must be a 'pathlib.Path'.")
120116
if not self.name:
121117
self.name = value.as_posix()
122-
self.value = value
118+
self.path = value
123119

124120
@classmethod
125121
@functools.lru_cache
@@ -131,7 +127,7 @@ def from_path(cls, path: Path) -> PathNode:
131127
"""
132128
if not path.is_absolute():
133129
raise ValueError("Node must be instantiated from absolute path.")
134-
return cls(name=path.as_posix(), value=path)
130+
return cls(name=path.as_posix(), path=path)
135131

136132
def state(self) -> str | None:
137133
"""Calculate the state of the node.
@@ -145,7 +141,7 @@ def state(self) -> str | None:
145141

146142
def load(self) -> Path:
147143
"""Load the value."""
148-
return self.value
144+
return self.path
149145

150146
def save(self, value: bytes | str) -> None:
151147
"""Save strings or bytes to file."""

tests/test_collect_command.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,8 @@ def test_print_collected_tasks_with_nodes(capsys):
385385
base_name="function",
386386
path=Path("task_path.py"),
387387
function=function,
388-
depends_on={
389-
"depends_on": PathNode(name="in.txt", value=Path("in.txt"))
390-
},
391-
produces={0: PathNode(name="out.txt", value=Path("out.txt"))},
388+
depends_on={"depends_on": PathNode(name="in.txt", path=Path("in.txt"))},
389+
produces={0: PathNode(name="out.txt", path=Path("out.txt"))},
392390
)
393391
]
394392
}

0 commit comments

Comments
 (0)