funcnodes-basic 0.1.10__tar.gz → 0.1.11__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcnodes-basic
3
- Version: 0.1.10
3
+ Version: 0.1.11
4
4
  Summary: Basic functionalities for funcnodes
5
5
  License: MIT
6
6
  Author: Julian Kimmig
@@ -6,7 +6,7 @@ from .strings import NODE_SHELF as strings_shelf
6
6
  from .dicts import NODE_SHELF as dicts_shelf
7
7
 
8
8
 
9
- __version__ = "0.1.10"
9
+ __version__ = "0.1.11"
10
10
 
11
11
  NODE_SHELF = Shelf(
12
12
  nodes=[],
@@ -11,52 +11,30 @@ def contains(collection: List[Union[str, Any]], item: Union[str, Any]) -> bool:
11
11
  return item in collection
12
12
 
13
13
 
14
- class GetIndexNode(fn.Node):
15
- node_id = "list.get"
16
- node_name = "Get Element"
17
- description = "Gets an element from a list."
18
- inputlist = fn.NodeInput(
19
- name="List",
20
- type=List[Union[str, Any]],
21
- uuid="inputlist",
22
- )
23
-
24
- index = fn.NodeInput(
25
- name="Index",
26
- type=int,
27
- uuid="index",
28
- )
29
-
30
- element = fn.NodeOutput(
31
- name="Element",
32
- type=Any,
33
- uuid="element",
34
- )
35
-
36
- def __init__(self, *args, **kwargs):
37
- super().__init__(*args, **kwargs)
38
- self.get_input("inputlist").on("after_set_value", self._update_indices)
39
-
40
- def _update_indices(self, **kwargs):
41
- try:
42
- lst = self.get_input("inputlist").value
43
- index = self.get_input("index")
44
- except KeyError:
45
- return
46
- try:
47
- index.update_value_options(min=0, max=len(lst) - 1)
48
- except Exception:
49
- index.update_value_options(min=0, max=0)
50
-
51
- async def func(
52
- self,
53
- inputlist: List[Any],
54
- index: int,
55
- ) -> Any:
56
- index = int(index)
57
- ele = inputlist[index]
58
- self.get_output("element").value = ele
59
- return ele
14
+ @fn.NodeDecorator(
15
+ id="list_get",
16
+ name="Get Element",
17
+ description="Gets an element from a list.",
18
+ default_io_options={
19
+ "lst": {
20
+ "on": {
21
+ "after_set_value": fn.decorator.update_other_io_value_options(
22
+ "index",
23
+ lambda result: {
24
+ "min": -len(result),
25
+ "max": len(result) - 1 if len(result) > 0 else 0,
26
+ },
27
+ )
28
+ }
29
+ },
30
+ },
31
+ outputs=[
32
+ {"name": "element"},
33
+ ],
34
+ )
35
+ def list_get(lst: List[Any], index: int = -1) -> Tuple[Any]:
36
+ # shallow copy the list
37
+ return lst[index]
60
38
 
61
39
 
62
40
  @fn.NodeDecorator(
@@ -102,7 +80,10 @@ def list_extend(lst: List[Any], items: List[Any]) -> List[Any]:
102
80
  "on": {
103
81
  "after_set_value": fn.decorator.update_other_io_value_options(
104
82
  "index",
105
- lambda result: {"min": 0, "max": len(result) - 1},
83
+ lambda result: {
84
+ "min": -len(result),
85
+ "max": len(result) - 1 if len(result) > 0 else 0,
86
+ },
106
87
  )
107
88
  }
108
89
  },
@@ -112,7 +93,7 @@ def list_extend(lst: List[Any], items: List[Any]) -> List[Any]:
112
93
  {"name": "item"},
113
94
  ],
114
95
  )
115
- def list_pop(lst: List[Any], index: int) -> Tuple[List[Any], Any]:
96
+ def list_pop(lst: List[Any], index: int = -1) -> Tuple[List[Any], Any]:
116
97
  # shallow copy the list
117
98
  lst = copy.copy(lst)
118
99
  item = lst.pop(index)
@@ -177,13 +158,16 @@ def list_count(lst: List[Any], item: Any) -> int:
177
158
  "on": {
178
159
  "after_set_value": fn.decorator.update_other_io_value_options(
179
160
  "index",
180
- lambda result: {"min": 0, "max": len(result)},
161
+ lambda result: {
162
+ "min": -len(result),
163
+ "max": len(result),
164
+ },
181
165
  )
182
166
  }
183
167
  },
184
168
  },
185
169
  )
186
- def list_insert(lst: List[Any], index: int, item: Any) -> List[Any]:
170
+ def list_insert(lst: List[Any], item: Any, index: int = -1) -> List[Any]:
187
171
  lst = copy.copy(lst)
188
172
  lst.insert(index, item)
189
173
  return lst
@@ -197,13 +181,16 @@ def list_insert(lst: List[Any], index: int, item: Any) -> List[Any]:
197
181
  "on": {
198
182
  "after_set_value": fn.decorator.update_other_io_value_options(
199
183
  "index",
200
- lambda result: {"min": 0, "max": len(result) - 1},
184
+ lambda result: {
185
+ "min": -len(result),
186
+ "max": len(result) - 1 if len(result) > 0 else 0,
187
+ },
201
188
  )
202
189
  }
203
190
  },
204
191
  },
205
192
  )
206
- def list_set(lst: List[Any], index: int, item: Any) -> List[Any]:
193
+ def list_set(lst: List[Any], item: Any, index: int = -1) -> List[Any]:
207
194
  lst = copy.copy(lst)
208
195
  lst[index] = item
209
196
  return lst
@@ -250,7 +237,7 @@ def list_slice_step(
250
237
  NODE_SHELF = fn.Shelf(
251
238
  nodes=[
252
239
  contains,
253
- GetIndexNode,
240
+ list_get,
254
241
  to_list,
255
242
  list_length,
256
243
  list_append,
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "funcnodes-basic"
3
- version = "0.1.10"
3
+ version = "0.1.11"
4
4
  description = "Basic functionalities for funcnodes"
5
5
  authors = ["Julian Kimmig <julian.kimmig@gmx.net>"]
6
6
  readme = "README.md"
@@ -21,7 +21,7 @@ funcnodes = "*"
21
21
  [tool.poetry.group.dev.dependencies]
22
22
  pytest = "*"
23
23
  pre-commit = "*"
24
- funcnodes-module = "*"
24
+ funcnodes-module = "^0.1.19"
25
25
 
26
26
  [build-system]
27
27
  requires = ["poetry-core"]