Skip to content

Commit 7b1a08f

Browse files
committed
Rename decorator to signature
1 parent ee43f7d commit 7b1a08f

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

jmespath/functions.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ def populate_function_table(cls):
4444
return cls
4545

4646

47-
def builtin_function(*arguments):
48-
def _record_arity(func):
47+
def signature(*arguments):
48+
def _record_signature(func):
4949
func.signature = arguments
5050
return func
51-
return _record_arity
51+
return _record_signature
5252

5353

5454
@populate_function_table
5555
class RuntimeFunctions(object):
5656
# 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.
5858

5959
FUNCTION_TABLE = {
6060
}
@@ -151,36 +151,36 @@ def _subtype_check(self, current, allowed_subtypes, types, function_name):
151151
raise exceptions.JMESPathTypeError(
152152
function_name, element, actual_typename, types)
153153

154-
@builtin_function({'types': ['number']})
154+
@signature({'types': ['number']})
155155
def _func_abs(self, arg):
156156
return abs(arg)
157157

158-
@builtin_function({'types': ['array-number']})
158+
@signature({'types': ['array-number']})
159159
def _func_avg(self, arg):
160160
return sum(arg) / float(len(arg))
161161

162-
@builtin_function({'types': [], 'variadic': True})
162+
@signature({'types': [], 'variadic': True})
163163
def _func_not_null(self, *arguments):
164164
for argument in arguments:
165165
if argument is not None:
166166
return argument
167167

168-
@builtin_function({'types': []})
168+
@signature({'types': []})
169169
def _func_to_array(self, arg):
170170
if isinstance(arg, list):
171171
return arg
172172
else:
173173
return [arg]
174174

175-
@builtin_function({'types': []})
175+
@signature({'types': []})
176176
def _func_to_string(self, arg):
177177
if isinstance(arg, STRING_TYPE):
178178
return arg
179179
else:
180180
return json.dumps(arg, separators=(',', ':'),
181181
default=str)
182182

183-
@builtin_function({'types': []})
183+
@signature({'types': []})
184184
def _func_to_number(self, arg):
185185
if isinstance(arg, (list, dict, bool)):
186186
return None
@@ -197,88 +197,88 @@ def _func_to_number(self, arg):
197197
except ValueError:
198198
return None
199199

200-
@builtin_function({'types': ['array', 'string']}, {'types': []})
200+
@signature({'types': ['array', 'string']}, {'types': []})
201201
def _func_contains(self, subject, search):
202202
return search in subject
203203

204-
@builtin_function({'types': ['string', 'array', 'object']})
204+
@signature({'types': ['string', 'array', 'object']})
205205
def _func_length(self, arg):
206206
return len(arg)
207207

208-
@builtin_function({'types': ['string']}, {'types': ['string']})
208+
@signature({'types': ['string']}, {'types': ['string']})
209209
def _func_ends_with(self, search, suffix):
210210
return search.endswith(suffix)
211211

212-
@builtin_function({'types': ['string']}, {'types': ['string']})
212+
@signature({'types': ['string']}, {'types': ['string']})
213213
def _func_starts_with(self, search, suffix):
214214
return search.startswith(suffix)
215215

216-
@builtin_function({'types': ['array', 'string']})
216+
@signature({'types': ['array', 'string']})
217217
def _func_reverse(self, arg):
218218
if isinstance(arg, STRING_TYPE):
219219
return arg[::-1]
220220
else:
221221
return list(reversed(arg))
222222

223-
@builtin_function({"types": ['number']})
223+
@signature({"types": ['number']})
224224
def _func_ceil(self, arg):
225225
return math.ceil(arg)
226226

227-
@builtin_function({"types": ['number']})
227+
@signature({"types": ['number']})
228228
def _func_floor(self, arg):
229229
return math.floor(arg)
230230

231-
@builtin_function({"types": ['string']}, {"types": ['array-string']})
231+
@signature({"types": ['string']}, {"types": ['array-string']})
232232
def _func_join(self, separator, array):
233233
return separator.join(array)
234234

235-
@builtin_function({'types': ['expref']}, {'types': ['array']})
235+
@signature({'types': ['expref']}, {'types': ['array']})
236236
def _func_map(self, expref, arg):
237237
result = []
238238
for element in arg:
239239
result.append(expref.visit(expref.expression, element))
240240
return result
241241

242-
@builtin_function({"types": ['array-number', 'array-string']})
242+
@signature({"types": ['array-number', 'array-string']})
243243
def _func_max(self, arg):
244244
if arg:
245245
return max(arg)
246246
else:
247247
return None
248248

249-
@builtin_function({"types": ["object"], "variadic": True})
249+
@signature({"types": ["object"], "variadic": True})
250250
def _func_merge(self, *arguments):
251251
merged = {}
252252
for arg in arguments:
253253
merged.update(arg)
254254
return merged
255255

256-
@builtin_function({"types": ['array-number', 'array-string']})
256+
@signature({"types": ['array-number', 'array-string']})
257257
def _func_min(self, arg):
258258
if arg:
259259
return min(arg)
260260
else:
261261
return None
262262

263-
@builtin_function({"types": ['array-string', 'array-number']})
263+
@signature({"types": ['array-string', 'array-number']})
264264
def _func_sort(self, arg):
265265
return list(sorted(arg))
266266

267-
@builtin_function({"types": ['array-number']})
267+
@signature({"types": ['array-number']})
268268
def _func_sum(self, arg):
269269
return sum(arg)
270270

271-
@builtin_function({"types": ['object']})
271+
@signature({"types": ['object']})
272272
def _func_keys(self, arg):
273273
# To be consistent with .values()
274274
# should we also return the indices of a list?
275275
return list(arg.keys())
276276

277-
@builtin_function({"types": ['object']})
277+
@signature({"types": ['object']})
278278
def _func_values(self, arg):
279279
return list(arg.values())
280280

281-
@builtin_function({'types': []})
281+
@signature({'types': []})
282282
def _func_type(self, arg):
283283
if isinstance(arg, STRING_TYPE):
284284
return "string"
@@ -293,7 +293,7 @@ def _func_type(self, arg):
293293
elif arg is None:
294294
return "null"
295295

296-
@builtin_function({'types': ['array']}, {'types': ['expref']})
296+
@signature({'types': ['array']}, {'types': ['expref']})
297297
def _func_sort_by(self, array, expref):
298298
if not array:
299299
return array
@@ -313,14 +313,14 @@ def _func_sort_by(self, array, expref):
313313
'sort_by')
314314
return list(sorted(array, key=keyfunc))
315315

316-
@builtin_function({'types': ['array']}, {'types': ['expref']})
316+
@signature({'types': ['array']}, {'types': ['expref']})
317317
def _func_min_by(self, array, expref):
318318
keyfunc = self._create_key_func(expref,
319319
['number', 'string'],
320320
'min_by')
321321
return min(array, key=keyfunc)
322322

323-
@builtin_function({'types': ['array']}, {'types': ['expref']})
323+
@signature({'types': ['array']}, {'types': ['expref']})
324324
def _func_max_by(self, array, expref):
325325
keyfunc = self._create_key_func(expref,
326326
['number', 'string'],

0 commit comments

Comments
 (0)