From 506b78144c89e1371d2e9dbde4315aa769629ae4 Mon Sep 17 00:00:00 2001 From: Marvin Poul Date: Mon, 24 Feb 2025 10:24:47 +0100 Subject: [PATCH 1/4] Add unit test --- tests/unit/nodes/test_transform.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/nodes/test_transform.py b/tests/unit/nodes/test_transform.py index e9bef9d6f..3e136a458 100644 --- a/tests/unit/nodes/test_transform.py +++ b/tests/unit/nodes/test_transform.py @@ -1,3 +1,4 @@ +from abc import ABC, abstractmethod import pickle import random import unittest @@ -249,6 +250,23 @@ class DecoratedDCLike: "instantiation", ) + with self.subTest("From instantiated ABC"): + + class MyAbstractData(ABC): + @abstractmethod + def shout(self): + pass + + try: + @as_dataclass_node + class MyConcreteData(MyAbstractData): + name: str + def shout(self): + return f"!{self.name}!" + except: + self.fail("Wrapping an implementation of an ABC should not raise exceptions!") + + def test_dataclass_typing_and_storage(self): md = MyData() From 75e4dc65fd5165aefb2351d2aad7ea02066fe67e Mon Sep 17 00:00:00 2001 From: Marvin Poul Date: Sat, 22 Feb 2025 11:21:26 +0100 Subject: [PATCH 2/4] Use instance check instead of equality in as_dataclass_node type(cls) is only equal to type if no other meta class has been used. This includes classes derived from ABC, so it is a bit inconvenient. Using the instance check however seems to work in these cases. --- pyiron_workflow/nodes/transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_workflow/nodes/transform.py b/pyiron_workflow/nodes/transform.py index 6a4371bed..c3c861a91 100644 --- a/pyiron_workflow/nodes/transform.py +++ b/pyiron_workflow/nodes/transform.py @@ -386,7 +386,7 @@ def _extra_info(cls) -> str: def dataclass_node_factory( dataclass: type, use_cache: bool = True, / ) -> type[DataclassNode]: - if type(dataclass) is not type: + if not isinstance(dataclass, type): raise TypeError( f"{DataclassNode} expected to get a dataclass but {dataclass} is not " f"type `type`." From 01b41a19475cf445fb0e3beefe1be823fa064a84 Mon Sep 17 00:00:00 2001 From: Marvin Poul Date: Mon, 24 Feb 2025 15:36:35 +0100 Subject: [PATCH 3/4] Silence ruff --- tests/unit/nodes/test_transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/nodes/test_transform.py b/tests/unit/nodes/test_transform.py index 3e136a458..5fc1cbf37 100644 --- a/tests/unit/nodes/test_transform.py +++ b/tests/unit/nodes/test_transform.py @@ -263,7 +263,7 @@ class MyConcreteData(MyAbstractData): name: str def shout(self): return f"!{self.name}!" - except: + except: # noqa: E722 self.fail("Wrapping an implementation of an ABC should not raise exceptions!") From e79c196449f7444cad010db363c263d398bf627f Mon Sep 17 00:00:00 2001 From: Marvin Poul Date: Wed, 26 Feb 2025 09:58:45 +0100 Subject: [PATCH 4/4] Reorder imports --- tests/unit/nodes/test_transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/nodes/test_transform.py b/tests/unit/nodes/test_transform.py index 5fc1cbf37..156cf87ee 100644 --- a/tests/unit/nodes/test_transform.py +++ b/tests/unit/nodes/test_transform.py @@ -1,7 +1,7 @@ -from abc import ABC, abstractmethod import pickle import random import unittest +from abc import ABC, abstractmethod from dataclasses import dataclass, field, is_dataclass from pandas import DataFrame