Skip to content

Commit 22f68d3

Browse files
author
Leandro Inocencio
committed
add wrappers for build-in modules
1 parent a10c8eb commit 22f68d3

File tree

7 files changed

+342
-23
lines changed

7 files changed

+342
-23
lines changed

example_auto_nodes/module_nodes.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@
22
get_functions_from_module,
33
get_functions_from_type)
44

5-
import math
65
import os
76
import sys
87
import random
98
import numpy
109
import numpydoc.docscrape
1110
import inspect
1211

13-
# add basic math functions to math library
14-
math.add = lambda x, y: x + y
15-
math.sub = lambda x, y: x - y
16-
math.mul = lambda x, y: x * y
17-
math.div = lambda x, y: x / y
18-
19-
20-
def get_value(self,index):
21-
return self[index]
22-
23-
24-
def get_item(self,index):
25-
return self.items()[index]
12+
import example_auto_nodes.wrappers.math as _math
13+
import example_auto_nodes.wrappers.list as _list
14+
import example_auto_nodes.wrappers.dict as _dict
15+
import example_auto_nodes.wrappers.str as _str
16+
import example_auto_nodes.wrappers.tuple as _tuple
2617

2718

2819
class MathModuleNode(ModuleNode):
@@ -36,7 +27,7 @@ class MathModuleNode(ModuleNode):
3627
# set the initial default node name.
3728
NODE_NAME = 'math module'
3829

39-
module_functions = get_functions_from_type(math)
30+
module_functions = get_functions_from_type(_math)
4031

4132
def __init__(self):
4233
super(MathModuleNode, self).__init__(float, float)
@@ -162,8 +153,8 @@ class StringFunctionsNode(ModuleNode):
162153
# set the initial default node name.
163154
NODE_NAME = 'String Functions'
164155

165-
module_functions = get_functions_from_type(str)
166-
module_functions["get value"] = get_value
156+
module_functions = get_functions_from_type(_str)
157+
167158

168159
def __init__(self):
169160
super(StringFunctionsNode, self).__init__()
@@ -180,8 +171,7 @@ class ListFunctionsNode(ModuleNode):
180171
# set the initial default node name.
181172
NODE_NAME = 'List Functions'
182173

183-
module_functions = get_functions_from_type(list)
184-
module_functions["get value"] = get_value
174+
module_functions = get_functions_from_type(_list)
185175

186176
def __init__(self):
187177
super(ListFunctionsNode, self).__init__()
@@ -198,8 +188,7 @@ class DictFunctionsNode(ModuleNode):
198188
# set the initial default node name.
199189
NODE_NAME = 'Dict Functions'
200190

201-
module_functions = get_functions_from_type(list)
202-
module_functions["get item"] = get_item
191+
module_functions = get_functions_from_type(_dict)
203192

204193
def __init__(self):
205194
super(DictFunctionsNode, self).__init__()
@@ -216,8 +205,7 @@ class TupleFunctionsNode(ModuleNode):
216205
# set the initial default node name.
217206
NODE_NAME = 'Tuple Functions'
218207

219-
module_functions = get_functions_from_type(tuple)
220-
module_functions["get value"] = get_value
208+
module_functions = get_functions_from_type(_tuple)
221209

222210
def __init__(self):
223211
super(TupleFunctionsNode, self).__init__()

example_auto_nodes/wrappers/__init__.py

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
def clear(self):
2+
self.clear()
3+
return self
4+
5+
6+
def copy(self):
7+
return self.copy()
8+
9+
10+
def fromkeys(self, iterable, value=None):
11+
return self.fromkeys(iterable, value)
12+
13+
14+
def get(self, key, default=None):
15+
return self.get(key, default)
16+
17+
18+
def items(self):
19+
return list(self.items())
20+
21+
22+
def keys(self):
23+
return list(self.keys())
24+
25+
26+
def pop(self, index):
27+
return self.pop(index)
28+
29+
30+
def popitem(self):
31+
return self.popitem()
32+
33+
34+
def setdefault(self, key, default=None):
35+
self.setdefault(key, default)
36+
return self
37+
38+
39+
def update(self, e):
40+
self.update(e)
41+
return self
42+
43+
44+
def values(self):
45+
return list(self.values())
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
def append(self, object):
2+
self.append(object)
3+
return self
4+
5+
6+
def clear(self):
7+
self.clear()
8+
return self
9+
10+
11+
def copy(self):
12+
return self.copy()
13+
14+
15+
def count(self, value):
16+
return self.count(value)
17+
18+
19+
def extend(self, iterable):
20+
self.extend(iterable)
21+
return self
22+
23+
def index(self, value):
24+
return self.index(value)
25+
26+
27+
def insert(self, index, obj):
28+
self.insert(index, obj)
29+
return self
30+
31+
32+
def pop(self, index=-1):
33+
return self.pop(index)
34+
35+
36+
def remove(self, value):
37+
return self.remove(value)
38+
39+
40+
def reverse(self):
41+
self.reverse()
42+
return self
43+
44+
45+
def sort(self):
46+
self.sort()
47+
return self
48+
49+
50+
# custom functions
51+
def get(self, index):
52+
return self.__getitem__(index)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from math import *
2+
3+
_pi = pi
4+
_e = e
5+
_tau = tau
6+
_inf = inf
7+
_nan = nan
8+
9+
10+
# add contants as functions
11+
12+
def pi():
13+
print('pi', _pi)
14+
return _pi
15+
16+
17+
def e():
18+
print('e', _e)
19+
return _e
20+
21+
22+
def tau():
23+
print('tau', _tau)
24+
return _tau
25+
26+
27+
def inf():
28+
print('inf', _inf)
29+
return _inf
30+
31+
32+
def nan():
33+
print('nan', _nan)
34+
return _nan
35+
36+
37+
# add basic math functions to math library
38+
39+
def add(x, y):
40+
return x + y
41+
42+
43+
def sub(x, y):
44+
return x - y
45+
46+
47+
def mul(x, y):
48+
return x * y
49+
50+
51+
def div(x, y):
52+
return x / y

0 commit comments

Comments
 (0)