@@ -44,17 +44,17 @@ def populate_function_table(cls):
44
44
return cls
45
45
46
46
47
- def builtin_function (* arguments ):
48
- def _record_arity (func ):
47
+ def signature (* arguments ):
48
+ def _record_signature (func ):
49
49
func .signature = arguments
50
50
return func
51
- return _record_arity
51
+ return _record_signature
52
52
53
53
54
54
@populate_function_table
55
55
class RuntimeFunctions (object ):
56
56
# The built in functions are automatically populated in the FUNCTION_TABLE
57
- # using the @builtin_function decorator on methods defined in this class.
57
+ # using the @signature decorator on methods defined in this class.
58
58
59
59
FUNCTION_TABLE = {
60
60
}
@@ -151,36 +151,36 @@ def _subtype_check(self, current, allowed_subtypes, types, function_name):
151
151
raise exceptions .JMESPathTypeError (
152
152
function_name , element , actual_typename , types )
153
153
154
- @builtin_function ({'types' : ['number' ]})
154
+ @signature ({'types' : ['number' ]})
155
155
def _func_abs (self , arg ):
156
156
return abs (arg )
157
157
158
- @builtin_function ({'types' : ['array-number' ]})
158
+ @signature ({'types' : ['array-number' ]})
159
159
def _func_avg (self , arg ):
160
160
return sum (arg ) / float (len (arg ))
161
161
162
- @builtin_function ({'types' : [], 'variadic' : True })
162
+ @signature ({'types' : [], 'variadic' : True })
163
163
def _func_not_null (self , * arguments ):
164
164
for argument in arguments :
165
165
if argument is not None :
166
166
return argument
167
167
168
- @builtin_function ({'types' : []})
168
+ @signature ({'types' : []})
169
169
def _func_to_array (self , arg ):
170
170
if isinstance (arg , list ):
171
171
return arg
172
172
else :
173
173
return [arg ]
174
174
175
- @builtin_function ({'types' : []})
175
+ @signature ({'types' : []})
176
176
def _func_to_string (self , arg ):
177
177
if isinstance (arg , STRING_TYPE ):
178
178
return arg
179
179
else :
180
180
return json .dumps (arg , separators = (',' , ':' ),
181
181
default = str )
182
182
183
- @builtin_function ({'types' : []})
183
+ @signature ({'types' : []})
184
184
def _func_to_number (self , arg ):
185
185
if isinstance (arg , (list , dict , bool )):
186
186
return None
@@ -197,88 +197,88 @@ def _func_to_number(self, arg):
197
197
except ValueError :
198
198
return None
199
199
200
- @builtin_function ({'types' : ['array' , 'string' ]}, {'types' : []})
200
+ @signature ({'types' : ['array' , 'string' ]}, {'types' : []})
201
201
def _func_contains (self , subject , search ):
202
202
return search in subject
203
203
204
- @builtin_function ({'types' : ['string' , 'array' , 'object' ]})
204
+ @signature ({'types' : ['string' , 'array' , 'object' ]})
205
205
def _func_length (self , arg ):
206
206
return len (arg )
207
207
208
- @builtin_function ({'types' : ['string' ]}, {'types' : ['string' ]})
208
+ @signature ({'types' : ['string' ]}, {'types' : ['string' ]})
209
209
def _func_ends_with (self , search , suffix ):
210
210
return search .endswith (suffix )
211
211
212
- @builtin_function ({'types' : ['string' ]}, {'types' : ['string' ]})
212
+ @signature ({'types' : ['string' ]}, {'types' : ['string' ]})
213
213
def _func_starts_with (self , search , suffix ):
214
214
return search .startswith (suffix )
215
215
216
- @builtin_function ({'types' : ['array' , 'string' ]})
216
+ @signature ({'types' : ['array' , 'string' ]})
217
217
def _func_reverse (self , arg ):
218
218
if isinstance (arg , STRING_TYPE ):
219
219
return arg [::- 1 ]
220
220
else :
221
221
return list (reversed (arg ))
222
222
223
- @builtin_function ({"types" : ['number' ]})
223
+ @signature ({"types" : ['number' ]})
224
224
def _func_ceil (self , arg ):
225
225
return math .ceil (arg )
226
226
227
- @builtin_function ({"types" : ['number' ]})
227
+ @signature ({"types" : ['number' ]})
228
228
def _func_floor (self , arg ):
229
229
return math .floor (arg )
230
230
231
- @builtin_function ({"types" : ['string' ]}, {"types" : ['array-string' ]})
231
+ @signature ({"types" : ['string' ]}, {"types" : ['array-string' ]})
232
232
def _func_join (self , separator , array ):
233
233
return separator .join (array )
234
234
235
- @builtin_function ({'types' : ['expref' ]}, {'types' : ['array' ]})
235
+ @signature ({'types' : ['expref' ]}, {'types' : ['array' ]})
236
236
def _func_map (self , expref , arg ):
237
237
result = []
238
238
for element in arg :
239
239
result .append (expref .visit (expref .expression , element ))
240
240
return result
241
241
242
- @builtin_function ({"types" : ['array-number' , 'array-string' ]})
242
+ @signature ({"types" : ['array-number' , 'array-string' ]})
243
243
def _func_max (self , arg ):
244
244
if arg :
245
245
return max (arg )
246
246
else :
247
247
return None
248
248
249
- @builtin_function ({"types" : ["object" ], "variadic" : True })
249
+ @signature ({"types" : ["object" ], "variadic" : True })
250
250
def _func_merge (self , * arguments ):
251
251
merged = {}
252
252
for arg in arguments :
253
253
merged .update (arg )
254
254
return merged
255
255
256
- @builtin_function ({"types" : ['array-number' , 'array-string' ]})
256
+ @signature ({"types" : ['array-number' , 'array-string' ]})
257
257
def _func_min (self , arg ):
258
258
if arg :
259
259
return min (arg )
260
260
else :
261
261
return None
262
262
263
- @builtin_function ({"types" : ['array-string' , 'array-number' ]})
263
+ @signature ({"types" : ['array-string' , 'array-number' ]})
264
264
def _func_sort (self , arg ):
265
265
return list (sorted (arg ))
266
266
267
- @builtin_function ({"types" : ['array-number' ]})
267
+ @signature ({"types" : ['array-number' ]})
268
268
def _func_sum (self , arg ):
269
269
return sum (arg )
270
270
271
- @builtin_function ({"types" : ['object' ]})
271
+ @signature ({"types" : ['object' ]})
272
272
def _func_keys (self , arg ):
273
273
# To be consistent with .values()
274
274
# should we also return the indices of a list?
275
275
return list (arg .keys ())
276
276
277
- @builtin_function ({"types" : ['object' ]})
277
+ @signature ({"types" : ['object' ]})
278
278
def _func_values (self , arg ):
279
279
return list (arg .values ())
280
280
281
- @builtin_function ({'types' : []})
281
+ @signature ({'types' : []})
282
282
def _func_type (self , arg ):
283
283
if isinstance (arg , STRING_TYPE ):
284
284
return "string"
@@ -293,7 +293,7 @@ def _func_type(self, arg):
293
293
elif arg is None :
294
294
return "null"
295
295
296
- @builtin_function ({'types' : ['array' ]}, {'types' : ['expref' ]})
296
+ @signature ({'types' : ['array' ]}, {'types' : ['expref' ]})
297
297
def _func_sort_by (self , array , expref ):
298
298
if not array :
299
299
return array
@@ -313,14 +313,14 @@ def _func_sort_by(self, array, expref):
313
313
'sort_by' )
314
314
return list (sorted (array , key = keyfunc ))
315
315
316
- @builtin_function ({'types' : ['array' ]}, {'types' : ['expref' ]})
316
+ @signature ({'types' : ['array' ]}, {'types' : ['expref' ]})
317
317
def _func_min_by (self , array , expref ):
318
318
keyfunc = self ._create_key_func (expref ,
319
319
['number' , 'string' ],
320
320
'min_by' )
321
321
return min (array , key = keyfunc )
322
322
323
- @builtin_function ({'types' : ['array' ]}, {'types' : ['expref' ]})
323
+ @signature ({'types' : ['array' ]}, {'types' : ['expref' ]})
324
324
def _func_max_by (self , array , expref ):
325
325
keyfunc = self ._create_key_func (expref ,
326
326
['number' , 'string' ],
0 commit comments