6
6
7
7
8
8
def _equals (x , y ):
9
- if _is_special_integer_case (x , y ):
9
+ if _is_special_number_case (x , y ):
10
10
return False
11
11
else :
12
12
return x == y
13
13
14
14
15
- def _is_special_integer_case (x , y ):
15
+ def _is_special_number_case (x , y ):
16
16
# We need to special case comparing 0 or 1 to
17
17
# True/False. While normally comparing any
18
18
# integer other than 0/1 to True/False will always
@@ -29,23 +29,11 @@ def _is_special_integer_case(x, y):
29
29
# Also need to consider that:
30
30
# >>> 0 in [True, False]
31
31
# True
32
- if _is_boolean_int ( x ):
32
+ if _is_actual_number ( x ) and x in ( 0 , 1 ):
33
33
return isinstance (y , bool )
34
- elif _is_boolean_int ( y ):
34
+ elif _is_actual_number ( y ) and y in ( 0 , 1 ):
35
35
return isinstance (x , bool )
36
36
37
- def _is_boolean_int (num ):
38
- """
39
- For backwards compatibility, Python considers bool to be an int.
40
- This causes issues when doing type comparison with isinstance(x, int).
41
- This function ensures the value is an actual int respresenting a boolean.
42
- """
43
- return (
44
- not isinstance (num , bool )
45
- and isinstance (num , int )
46
- and num in (0 , 1 )
47
- )
48
-
49
37
50
38
def _is_comparable (x ):
51
39
# The spec doesn't officially support string types yet,
@@ -63,7 +51,7 @@ def _is_actual_number(x):
63
51
# True
64
52
# >>> isinstance(True, int)
65
53
# True
66
- if x is True or x is False :
54
+ if isinstance ( x , bool ) :
67
55
return False
68
56
return isinstance (x , Number )
69
57
@@ -269,7 +257,7 @@ def visit_and_expression(self, node, value):
269
257
270
258
def visit_not_expression (self , node , value ):
271
259
original_result = self .visit (node ['children' ][0 ], value )
272
- if type (original_result ) is int and original_result == 0 :
260
+ if _is_actual_number (original_result ) and original_result == 0 :
273
261
# Special case for 0, !0 should be false, not true.
274
262
# 0 is not a special cased integer in jmespath.
275
263
return False
0 commit comments