|
13 | 13 | from dataclasses import dataclass |
14 | 14 | from dataclasses import field |
15 | 15 | from pathlib import Path |
| 16 | +from typing import TYPE_CHECKING |
16 | 17 | from typing import Any |
| 18 | +from typing import cast |
17 | 19 |
|
18 | 20 | from _pytask.config_utils import find_project_root_and_config |
19 | 21 | from _pytask.data_catalog_utils import DATA_CATALOG_NAME_FIELD |
|
25 | 27 | from _pytask.pluginmanager import storage |
26 | 28 | from _pytask.session import Session |
27 | 29 |
|
| 30 | +if TYPE_CHECKING: |
| 31 | + from collections.abc import Callable |
| 32 | + |
28 | 33 | __all__ = ["DataCatalog"] |
29 | 34 |
|
30 | 35 |
|
@@ -118,13 +123,17 @@ def add(self, name: str, node: PNode | PProvisionalNode | Any = None) -> None: |
118 | 123 |
|
119 | 124 | if node is None: |
120 | 125 | filename = hashlib.sha256(name.encode()).hexdigest() |
| 126 | + # Plugins can provide node classes with different keyword-only |
| 127 | + # constructors. The path-node check below selects the supported call |
| 128 | + # shape at runtime. |
| 129 | + node_factory = cast("Callable[..., PNode]", self.default_node) |
121 | 130 | if _is_path_node_type(self.default_node): |
122 | 131 | assert self.path is not None |
123 | | - self._entries[name] = self.default_node( |
| 132 | + self._entries[name] = node_factory( |
124 | 133 | name=name, path=self.path / f"{filename}.pkl" |
125 | 134 | ) |
126 | 135 | else: |
127 | | - self._entries[name] = self.default_node(name=name) |
| 136 | + self._entries[name] = node_factory(name=name) |
128 | 137 | assert self.path is not None |
129 | 138 | self.path.joinpath(f"{filename}-node.pkl").write_bytes( |
130 | 139 | pickle.dumps(self._entries[name]) |
|
0 commit comments