Skip to content

Commit b614c30

Browse files
committed
Merge branch 'gmega-develop' into develop
PR #145 * gmega-develop: bugfix: reverse type of null should be NoneType, not None
2 parents 437b015 + 4a521f8 commit b614c30

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

jmespath/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'boolean': ('bool',),
2929
'array': ('list', '_Projection'),
3030
'object': ('dict', 'OrderedDict',),
31-
'null': ('None',),
31+
'null': ('NoneType',),
3232
'string': ('unicode', 'str'),
3333
'number': ('float', 'int', 'long'),
3434
'expref': ('_Expression',),

tests/test_custom_functions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
3+
import jmespath
4+
from jmespath import functions
5+
6+
7+
class CustomFunctions(functions.Functions):
8+
@functions.signature({'types': ['string', 'array', 'object', 'null']})
9+
def _func_length0(self, s):
10+
return 0 if s is None else len(s)
11+
12+
13+
class TestCustomFunctions(unittest.TestCase):
14+
def setUp(self):
15+
self.options = jmespath.Options(custom_functions=CustomFunctions())
16+
17+
def test_null_to_nonetype(self):
18+
data = {
19+
'a': {
20+
'b': [1, 2, 3]
21+
}
22+
}
23+
24+
self.assertEqual(jmespath.search('length0(a.b)', data, self.options), 3)
25+
self.assertEqual(jmespath.search('length0(a.c)', data, self.options), 0)

0 commit comments

Comments
 (0)