Skip to content

Commit aef45e9

Browse files
authored
Supports functions with no arguments (#26)
* consider supporting functions with no arguments * supports functions with no arguments * remove extra change * bumped version
1 parent bfbeb8f commit aef45e9

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

jmespath/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from jmespath import parser
22
from jmespath.visitor import Options
33

4-
__version__ = '1.1.2'
4+
__version__ = '1.1.3'
55

66

77
def compile(expression, options=None):

jmespath/functions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ def call_function(self, function_name, resolved_args, *args, **kwargs):
8888
return function(self, *resolved_args)
8989

9090
def _validate_arguments(self, args, signature, function_name):
91-
required_arguments_count = len([param for param in signature if not param.get('optional') or not param['optional']])
92-
optional_arguments_count = len([param for param in signature if param.get('optional') and param['optional']])
91+
92+
if len(signature) == 0:
93+
return self._type_check(args, signature, function_name)
94+
95+
required_arguments_count = len([param for param in signature if param and (not param.get('optional') or not param['optional'])])
96+
optional_arguments_count = len([param for param in signature if param and param.get('optional') and param['optional']])
9397
has_variadic = signature[-1].get('variadic') if signature != None else False
98+
9499
if has_variadic:
95100
if len(args) < len(signature):
96101
raise exceptions.VariadictArityError(

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='jmespath-community',
10-
version='1.1.2',
10+
version='1.1.3',
1111
description='JSON Matching Expressions',
1212
long_description=io.open('README.rst', encoding='utf-8').read(),
1313
author='James Saryerwinnie, Springcomp',

tests/test_signatures.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ def test_signature_with_variadic_arguments(self):
4040
self._functions._validate_arguments(['string'], signature, function_name)
4141
)
4242

43+
def test_signature_with_empty_argument(self):
44+
(function_name, signature) = self._make_test("_function_with_empty_argument")
45+
self._functions._validate_arguments([], signature, function_name)
46+
47+
def test_signature_with_no_arguments(self):
48+
(function_name, signature) = self._make_test("_function_with_no_arguments")
49+
self._functions._validate_arguments([], signature, function_name)
50+
4351
def _make_test(self, funcName):
4452
for name, method in compat.get_methods(TestFunctionSignatures):
4553
print(name)
@@ -64,6 +72,13 @@ def _function_with_variadic_arguments(self, arg1, *arguments):
6472
def _function_with_optional_arguments(self, arg1, opt1, opt2):
6573
return None
6674

75+
@functions.signature({})
76+
def _function_with_empty_argument(self):
77+
return None
78+
79+
@functions.signature()
80+
def _function_with_no_arguments(self):
81+
return None
6782

6883
if __name__ == '__main__':
6984
unittest.main()

0 commit comments

Comments
 (0)