From 9900fe0db9ce3e03d3507d838797cf315dabbe49 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Fri, 17 Jan 2025 12:00:22 -0800 Subject: [PATCH 1/2] Remove preview helper method 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 --- pyiron_workflow/mixin/preview.py | 16 ---------------- pyiron_workflow/nodes/transform.py | 12 +++++++----- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/pyiron_workflow/mixin/preview.py b/pyiron_workflow/mixin/preview.py index ec74f3e7c..e2cf1c84a 100644 --- a/pyiron_workflow/mixin/preview.py +++ b/pyiron_workflow/mixin/preview.py @@ -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 diff --git a/pyiron_workflow/nodes/transform.py b/pyiron_workflow/nodes/transform.py index ed38302cd..9d0780d24 100644 --- a/pyiron_workflow/nodes/transform.py +++ b/pyiron_workflow/nodes/transform.py @@ -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 @@ -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 ( @@ -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 ( @@ -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): From c4bf5feea83dc9af06cdb7027c27391f03267f37 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Fri, 17 Jan 2025 12:18:22 -0800 Subject: [PATCH 2/2] Remove unused import Signed-off-by: liamhuber --- pyiron_workflow/mixin/preview.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_workflow/mixin/preview.py b/pyiron_workflow/mixin/preview.py index e2cf1c84a..7ae1a1c11 100644 --- a/pyiron_workflow/mixin/preview.py +++ b/pyiron_workflow/mixin/preview.py @@ -15,7 +15,7 @@ import inspect from abc import ABC, abstractmethod from collections.abc import Callable -from functools import lru_cache, wraps +from functools import lru_cache from typing import ( TYPE_CHECKING, Any,