Skip to content

Commit 7d86c36

Browse files
committed
Merge branch 'jbryan-fix-handling-unusual-numbers' into develop
Merges #127 * jbryan-fix-handling-unusual-numbers: Add fix to changelog Add tests for number type fix Added fix for long and Decimal numeric types
2 parents c6c1923 + 9752fd7 commit 7d86c36

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Next Release (TBD)
2+
==================
3+
4+
* Fix issue where long types in py2 and ``Decimal`` types
5+
were not being evaluated as numbers
6+
(`issue 125 <https://github.com/jmespath/jmespath.py/issues/125>`__)
7+
8+
19
0.9.2
210
=====
311

jmespath/visitor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from jmespath import functions
44
from jmespath.compat import string_type
5+
from numbers import Number
56

67

78
def _equals(x, y):
@@ -52,7 +53,7 @@ def _is_actual_number(x):
5253
# True
5354
if x is True or x is False:
5455
return False
55-
return isinstance(x, (float, int))
56+
return isinstance(x, Number)
5657

5758

5859
class Options(object):

tests/test_search.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
import decimal
13
from tests import unittest, OrderedDict
24

35
import jmespath
@@ -43,3 +45,14 @@ def test_can_compare_strings(self):
4345
# This is python specific behavior that's not in the official spec
4446
# yet, but this was regression from 0.9.0 so it's been added back.
4547
self.assertTrue(jmespath.search('a < b', {'a': '2016', 'b': '2017'}))
48+
49+
@unittest.skipIf(not hasattr(sys, 'maxint'), 'Test requires long() type')
50+
def test_can_handle_long_ints(self):
51+
result = sys.maxint + 1
52+
self.assertEqual(jmespath.search('[?a >= `1`].a', [{'a': result}]),
53+
[result])
54+
55+
def test_can_handle_decimals_as_numeric_type(self):
56+
result = decimal.Decimal('3')
57+
self.assertEqual(jmespath.search('[?a >= `1`].a', [{'a': result}]),
58+
[result])

0 commit comments

Comments
 (0)