Skip to content

Commit

Permalink
Remove preview helper method
Browse files Browse the repository at this point in the history
The potential usage is limited to transform and for-loop modules, and the extra layer of misdirection does not feel worth the very minimal reduction in code duplication

Signed-off-by: liamhuber <[email protected]>
  • Loading branch information
liamhuber committed Jan 17, 2025
1 parent de767fa commit 9900fe0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
16 changes: 0 additions & 16 deletions pyiron_workflow/mixin/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,6 @@ def preview_io(cls) -> DotDict[str, dict]:
)


def builds_class_io(subclass_factory: Callable[..., type[HasIOPreview]]):
"""
A decorator for factories producing subclasses of `HasIOPreview` to invoke
:meth:`preview_io` after the class is created, thus ensuring the IO has been
constructed at the class level.
"""

@wraps(subclass_factory)
def wrapped(*args, **kwargs):
node_class = subclass_factory(*args, **kwargs)
node_class.preview_io()
return node_class

return wrapped


class ScrapesIO(HasIOPreview, ABC):
"""
A mixin class for scraping IO channel information from a specific class method's
Expand Down
12 changes: 7 additions & 5 deletions pyiron_workflow/nodes/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from pyiron_snippets.factory import classfactory

from pyiron_workflow.channels import NOT_DATA, NotData
from pyiron_workflow.mixin.preview import builds_class_io
from pyiron_workflow.nodes.static_io import StaticNode


Expand Down Expand Up @@ -107,7 +106,6 @@ def _build_outputs_preview(cls) -> dict[str, Any]:
return {f"item_{i}": None for i in range(cls._length)}


@builds_class_io
@classfactory
def inputs_to_list_factory(n: int, use_cache: bool = True, /) -> type[InputsToList]:
return (
Expand Down Expand Up @@ -137,10 +135,11 @@ def inputs_to_list(n: int, /, *node_args, use_cache: bool = True, **node_kwargs)
InputsToList: An instance of the dynamically created :class:`InputsToList`
subclass.
"""
return inputs_to_list_factory(n, use_cache)(*node_args, **node_kwargs)
cls = inputs_to_list_factory(n, use_cache)
cls.preview_io()
return cls(*node_args, **node_kwargs)


@builds_class_io
@classfactory
def list_to_outputs_factory(n: int, use_cache: bool = True, /) -> type[ListToOutputs]:
return (
Expand Down Expand Up @@ -172,7 +171,10 @@ def list_to_outputs(
ListToOutputs: An instance of the dynamically created :class:`ListToOutputs`
subclass.
"""
return list_to_outputs_factory(n, use_cache)(*node_args, **node_kwargs)

cls = list_to_outputs_factory(n, use_cache)
cls.preview_io()
return cls(*node_args, **node_kwargs)


class InputsToDict(FromManyInputs, ABC):
Expand Down

0 comments on commit 9900fe0

Please sign in to comment.