Skip to content

Commit 477e49e

Browse files
authored
Remove .value from Node protocol. (#408)
1 parent 449635e commit 477e49e

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

docs/source/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
2525
implementing their own nodes.
2626
- {pull}`404` allows to use function returns to define task products.
2727
- {pull}`405` allows to match function returns to node annotations with prefix trees.
28+
- {pull}`406` removes `.value` from `Node` protocol.
2829

2930
## 0.3.2 - 2023-06-07
3031

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: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from _pytask.node_protocols import MetaNode
1212
from _pytask.node_protocols import Node
13+
from _pytask.node_protocols import PPathNode
1314
from _pytask.tree_util import PyTree
1415
from _pytask.tree_util import tree_leaves
1516
from _pytask.tree_util import tree_structure
@@ -101,25 +102,21 @@ def add_report_section(self, when: str, key: str, content: str) -> None:
101102

102103

103104
@define(kw_only=True)
104-
class PathNode(Node):
105+
class PathNode(PPathNode):
105106
"""The class for a node which is a path."""
106107

107108
name: str = ""
108109
"""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
110+
path: Path | None = None
111+
"""The path to the file."""
115112

116113
def from_annot(self, value: Path) -> None:
117114
"""Set path and if other attributes are not set, set sensible defaults."""
118115
if not isinstance(value, Path):
119116
raise TypeError("'value' must be a 'pathlib.Path'.")
120117
if not self.name:
121118
self.name = value.as_posix()
122-
self.value = value
119+
self.path = value
123120

124121
@classmethod
125122
@functools.lru_cache
@@ -131,7 +128,7 @@ def from_path(cls, path: Path) -> PathNode:
131128
"""
132129
if not path.is_absolute():
133130
raise ValueError("Node must be instantiated from absolute path.")
134-
return cls(name=path.as_posix(), value=path)
131+
return cls(name=path.as_posix(), path=path)
135132

136133
def state(self) -> str | None:
137134
"""Calculate the state of the node.
@@ -145,7 +142,7 @@ def state(self) -> str | None:
145142

146143
def load(self) -> Path:
147144
"""Load the value."""
148-
return self.value
145+
return self.path
149146

150147
def save(self, value: bytes | str) -> None:
151148
"""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)