funcnodes-basic 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,9 +5,9 @@ from .lists import NODE_SHELF as lists_shelf
5
5
  from .strings import NODE_SHELF as strings_shelf
6
6
  from .dicts import NODE_SHELF as dicts_shelf
7
7
  from .input import NODE_SHELF as input_shelf
8
+ from .dataclass import NODE_SHELF as dataclass_shelf
8
9
 
9
-
10
- __version__ = "0.2.2"
10
+ __version__ = "0.2.3"
11
11
 
12
12
  NODE_SHELF = Shelf(
13
13
  nodes=[],
@@ -15,6 +15,7 @@ NODE_SHELF = Shelf(
15
15
  input_shelf,
16
16
  lists_shelf,
17
17
  dicts_shelf,
18
+ dataclass_shelf,
18
19
  strings_shelf,
19
20
  math_shelf,
20
21
  logic_shelf,
@@ -0,0 +1,64 @@
1
+ import dataclasses
2
+ import funcnodes_core as fn
3
+ from typing import Any, Dict
4
+
5
+
6
+ @fn.NodeDecorator(
7
+ id="dataclass.to_dict",
8
+ )
9
+ def dataclass_to_dict(instance: Any) -> Dict[str, Any]:
10
+ """
11
+ Convert a dataclass instance to a dictionary.
12
+
13
+ Args:
14
+ instance (object): The dataclass instance to convert.
15
+
16
+ Returns:
17
+ dict: The dictionary representation of the dataclass instance.
18
+ """
19
+ if not dataclasses.is_dataclass(instance):
20
+ raise TypeError(f"Expected a dataclass instance, got {type(instance)}")
21
+
22
+ return dataclasses.asdict(instance)
23
+
24
+
25
+ @fn.NodeDecorator(
26
+ id="dataclass.get_field",
27
+ default_io_options={
28
+ "instance": {
29
+ "on": {
30
+ "after_set_value": fn.decorator.update_other_io_value_options(
31
+ "field_name",
32
+ lambda result: {
33
+ "options": [field.name for field in dataclasses.fields(result)]
34
+ if dataclasses.is_dataclass(result)
35
+ else None,
36
+ },
37
+ )
38
+ }
39
+ }
40
+ },
41
+ )
42
+ def dataclass_get_field(instance: Any, field_name: str) -> Any:
43
+ """
44
+ Get a field value from a dataclass instance.
45
+ """
46
+ if not dataclasses.is_dataclass(instance):
47
+ raise TypeError(f"Expected a dataclass instance, got {type(instance)}")
48
+
49
+ if not hasattr(instance, field_name):
50
+ raise AttributeError(
51
+ f"{instance.__class__.__name__} has no field '{field_name}'"
52
+ )
53
+
54
+ return getattr(instance, field_name)
55
+
56
+
57
+ NODE_SHELF = fn.Shelf(
58
+ nodes=[
59
+ dataclass_to_dict,
60
+ dataclass_get_field,
61
+ ],
62
+ name="dataclass",
63
+ description="Nodes for working with dataclasses",
64
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcnodes-basic
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Basic functionalities for funcnodes
5
5
  Author-email: Julian Kimmig <julian.kimmig@linkdlab.de>
6
6
  License: AGPL-3.0
@@ -1,13 +1,14 @@
1
- funcnodes_basic/__init__.py,sha256=-Y8ZnYjuERjcJ1JET2VMwT3l8OVXgO_q16Af-ViZ3YA,583
1
+ funcnodes_basic/__init__.py,sha256=J9x7KEw491QUEh5Uwac9DrwOI0xJydob365Xo3vB3Lo,660
2
+ funcnodes_basic/dataclass.py,sha256=p7IjTek7XnHOxZCJnFHhmNtmYM1DpacmfuaUePvDQ7Y,1732
2
3
  funcnodes_basic/dicts.py,sha256=koNJEwIq9ryC7evBpnI-QmR7MBIbgUWqpPpwhB3M69Y,2507
3
4
  funcnodes_basic/input.py,sha256=FSHS1bIJ2dJc9NqWaJO0MxegRBERhfxFdkmDiwAuE6o,1654
4
5
  funcnodes_basic/lists.py,sha256=9kGnovK-oClFatslbIeYne27l2-EPEXZbr_6yQ1B1cY,5835
5
6
  funcnodes_basic/logic.py,sha256=YwIcAgDqxnmJoLVN_hk9XgqrOJvkx3zczx2DxgBliHU,4304
6
7
  funcnodes_basic/math_nodes.py,sha256=PasNf-1wAvbJ_c-_qeiIDaUVfgPQEREJApeUcTS4FQg,10586
7
8
  funcnodes_basic/strings.py,sha256=O6rcxBQJ5eYd765w_tolaD6xMwsNmtBjiPgJ_69tKyA,16429
8
- funcnodes_basic-0.2.2.dist-info/licenses/LICENSE,sha256=21Lj2q2SYKHMY4768_a3pr3q0jY2VYamAHipoodhMDc,34273
9
- funcnodes_basic-0.2.2.dist-info/METADATA,sha256=bsn7Tm2o61wEtJ8v4qTFdiEklTu7o0-KjHQJuqaVsiM,2001
10
- funcnodes_basic-0.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
11
- funcnodes_basic-0.2.2.dist-info/entry_points.txt,sha256=HZ0g1oDO8PrL_f6b09lfTrS-jXqbZrP0qYf1Km_pVxw,79
12
- funcnodes_basic-0.2.2.dist-info/top_level.txt,sha256=xYbcX5Jx-Ow3N3kgXtyvh8kuhCahb3eHBIZfMvkpVKI,16
13
- funcnodes_basic-0.2.2.dist-info/RECORD,,
9
+ funcnodes_basic-0.2.3.dist-info/licenses/LICENSE,sha256=21Lj2q2SYKHMY4768_a3pr3q0jY2VYamAHipoodhMDc,34273
10
+ funcnodes_basic-0.2.3.dist-info/METADATA,sha256=d_LxJhdF-wi7JwpXRlJwrIrWcnBNlK79CZu4DSCEfAo,2001
11
+ funcnodes_basic-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ funcnodes_basic-0.2.3.dist-info/entry_points.txt,sha256=HZ0g1oDO8PrL_f6b09lfTrS-jXqbZrP0qYf1Km_pVxw,79
13
+ funcnodes_basic-0.2.3.dist-info/top_level.txt,sha256=xYbcX5Jx-Ow3N3kgXtyvh8kuhCahb3eHBIZfMvkpVKI,16
14
+ funcnodes_basic-0.2.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5