Skip to content

Commit 0394656

Browse files
committed
Merge branch 'develop' of https://github.com/jmespath/jmespath.py into develop
2 parents 52efa9d + b614c30 commit 0394656

File tree

10 files changed

+42
-17
lines changed

10 files changed

+42
-17
lines changed

docs/proposals/filter-expressions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ element resolves to the comparison ``"char" < "bar"``, and because these types
143143
are string, the expression results in ``null``, so the first element is not
144144
included in the result list. The second element resolves to ``2 < 1``,
145145
which is ``false``, so the second element is excluded from the result list.
146-
The third expression resolves to ``1 < 2`` which evalutes to ``true``, so the
146+
The third expression resolves to ``1 < 2`` which evaluates to ``true``, so the
147147
third element is included in the list. The final result of that expression
148148
is ``[{"a": 1, "b": 2}]``.
149149

@@ -247,7 +247,7 @@ In order for this to be useful we need to define what corresponds to true and
247247
false values, e.g. an empty list is a false value. Additionally, "or
248248
expressions" would need to change its semantics to branch based on the
249249
true/false value of an expression instead of whether or not the expression
250-
evalutes to null.
250+
evaluates to null.
251251

252252
This is certainly a direction to take in the future, adding arbitrary
253253
expressions in a filter would be a backwards compatible change, so it's not

docs/proposals/functions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Each function signature declares the types of its input parameters. If any
118118
type constraints are not met, implementations must indicate that an
119119
``invalid-type`` error occurred.
120120

121-
In order to accommodate type contraints, functions are provided to convert
121+
In order to accommodate type constraints, functions are provided to convert
122122
types to other types (``to_string``, ``to_number``) which are defined below.
123123
No explicit type conversion happens unless a user specifically uses one of
124124
these type conversion functions.

docs/proposals/improved-identifiers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ identifier cannot start with ``-``::
199199
escape.json
200200
-----------
201201

202-
The escape.json has several more interseting cases that need to be updated.
202+
The escape.json has several more interesting cases that need to be updated.
203203
This has to do with the updated escaping rules. Each one will be explained.
204204

205205
::

docs/proposals/pipes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The following modified JMESPath grammar supports piped expressions.
104104

105105
.. note::
106106

107-
``pipe-expression`` has a higher precendent than the ``or-operator``
107+
``pipe-expression`` has a higher precedent than the ``or-operator``
108108

109109
Compliance Tests
110110
================

docs/specification.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ SubExpressions
202202
"*" )
203203

204204
A subexpression is a combination of two expressions separated by the '.' char.
205-
A subexpression is evaluted as follows:
205+
A subexpression is evaluated as follows:
206206

207207
* Evaluate the expression on the left with the original JSON document.
208208
* Evaluate the expression on the right with the result of the left expression
@@ -455,7 +455,7 @@ evaluated as follows:
455455
1. A hash is created: ``{}``
456456
2. A key ``foo`` is created whose value is the result of evaluating ``one.two``
457457
against the provided JSON document: ``{"foo": evaluate(one.two, <data>)}``
458-
3. A key ``bar`` is created whose value is the result of evaluting the
458+
3. A key ``bar`` is created whose value is the result of evaluating the
459459
expression ``bar`` against the provided JSON document.
460460

461461
The final result will be: ``{"foo": "one-two", "bar": "bar"}``.
@@ -576,7 +576,7 @@ Filter Expressions
576576
A filter expression provides a way to select JSON elements based on a
577577
comparison to another expression. A filter expression is evaluated as follows:
578578
for each element in an array evaluate the ``list-filter-expr`` against the
579-
element. If the expression evalutes to ``true``, the item (in its entirety) is
579+
element. If the expression evaluates to ``true``, the item (in its entirety) is
580580
added to the result list. Otherwise it is excluded from the result list. A
581581
filter expression is only defined for a JSON array. Attempting to evaluate a
582582
filter expression against any other type will return ``null``.
@@ -606,7 +606,7 @@ For ``string/number/true/false/null`` types, equality is an exact match. A
606606
``string`` is equal to another ``string`` if they they have the exact sequence
607607
of code points. The literal values ``true/false/null`` are only equal to their
608608
own literal values. Two JSON objects are equal if they have the same set of
609-
keys and values (given two JSON objeccts ``x`` and ``y``, for each key value
609+
keys and values (given two JSON objects ``x`` and ``y``, for each key value
610610
pair ``(i, j)`` in ``x``, there exists an equivalent pair ``(i, j)`` in ``y``).
611611
Two JSON arrays are equal if they have equal elements in the same order (given
612612
two arrays ``x`` and ``y``, for each ``i`` from ``0`` until ``length(x)``,
@@ -629,7 +629,7 @@ element resolves to the comparison ``"char" < "bar"``, and because these types
629629
are string, the expression results in ``null``, so the first element is not
630630
included in the result list. The second element resolves to ``2 < 1``,
631631
which is ``false``, so the second element is excluded from the result list.
632-
The third expression resolves to ``1 < 2`` which evalutes to ``true``, so the
632+
The third expression resolves to ``1 < 2`` which evaluates to ``true``, so the
633633
third element is included in the list. The final result of that expression
634634
is ``[{"a": 1, "b": 2}]``.
635635

@@ -734,7 +734,7 @@ Each function signature declares the types of its input parameters. If any
734734
type constraints are not met, implementations must indicate that an
735735
``invalid-type`` error occurred.
736736

737-
In order to accommodate type contraints, functions are provided to convert
737+
In order to accommodate type constraints, functions are provided to convert
738738
types to other types (``to_string``, ``to_number``) which are defined below.
739739
No explicit type conversion happens unless a user specifically uses one of
740740
these type conversion functions.
@@ -1258,7 +1258,7 @@ not_null
12581258

12591259
Returns the first argument that does not resolve to ``null``. This function
12601260
accepts one or more arguments, and will evaluate them in order until a
1261-
non null argument is encounted. If all arguments values resolve to ``null``,
1261+
non null argument is encountered. If all arguments values resolve to ``null``,
12621262
then a value of ``null`` is returned.
12631263

12641264
.. list-table:: Examples

extra/test_hypothesis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737

3838

39-
# For all of these tests they verify these proprties:
39+
# For all of these tests they verify these properties:
4040
# either the operation succeeds or it raises a JMESPathError.
4141
# If any other exception is raised then we error out.
4242
@settings(**BASE_SETTINGS)

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',),

jmespath/visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ class Options(object):
6060
"""Options to control how a JMESPath function is evaluated."""
6161
def __init__(self, dict_cls=None, custom_functions=None):
6262
#: The class to use when creating a dict. The interpreter
63-
# may create dictionaries during the evalution of a JMESPath
63+
# may create dictionaries during the evaluation of a JMESPath
6464
# expression. For example, a multi-select hash will
6565
# create a dictionary. By default we use a dict() type.
6666
# You can set this value to change what dict type is used.
6767
# The most common reason you would change this is if you
6868
# want to set a collections.OrderedDict so that you can
69-
# have predictible key ordering.
69+
# have predictable key ordering.
7070
self.dict_cls = dict_cls
7171
self.custom_functions = custom_functions
7272

scripts/astrender

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main():
4242
svg_name = os.path.splitext(f.name)[0] + '.png'
4343
check_call('dot -Tpng %s -o %s' % (f.name, svg_name), shell=True)
4444
webbrowser.open('file://%s' % svg_name)
45-
# Rather than prompt the user to hit enterr
45+
# Rather than prompt the user to hit enter
4646
# just sleep for as long as we think is reasonable for
4747
# an application to open and display the png.
4848
time.sleep(2)

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)