File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -29,10 +29,22 @@ 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 type (x ) is int and (x == 0 or x == 1 ):
33
- return y is True or y is False
34
- elif type (y ) is int and (y == 0 or y == 1 ):
35
- return x is True or x is False
32
+ if _is_boolean_int (x ):
33
+ return isinstance (y , bool )
34
+ elif _is_boolean_int (y ):
35
+ return isinstance (x , bool )
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
+ )
36
48
37
49
38
50
def _is_comparable (x ):
You can’t perform that action at this time.
0 commit comments