True and False should not validate as int, long, float, and double
MODIFY
fastavro/_validation.pyx
fastavro/_validation.pyx
@@ -49,7 +49,8 @@ cdef inline bint validate_int(datum, schema=None,
str parent_ns='', bint raise_errors=True):
return (
(isinstance(datum, (int, long, numbers.Integral))
- and INT_MIN_VALUE <= datum <= INT_MAX_VALUE)
+ and INT_MIN_VALUE <= datum <= INT_MAX_VALUE
+ and not isinstance(datum, bool))
or isinstance(datum, (
datetime.time, datetime.datetime, datetime.date))
)
@@ -59,14 +60,18 @@ cdef inline bint validate_long(datum, schema=None,
str parent_ns='', bint raise_errors=True):
return (
(isinstance(datum, (int, long, numbers.Integral))
- and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
+ and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE
+ and not isinstance(datum, bool))
or isinstance(datum, (datetime.time, datetime.datetime, datetime.date))
)
cdef inline bint validate_float(datum, schema=None,
str parent_ns='', bint raise_errors=True):
- return isinstance(datum, (int, long, float, numbers.Real))
+ return (
+ isinstance(datum, (int, long, float, numbers.Real))
+ and not isinstance(datum, bool)
+ )
cdef inline bint validate_fixed(datum, dict schema,

MODIFY
fastavro/_validation_py.py
fastavro/_validation_py.py
@@ -93,7 +93,8 @@ def validate_int(datum, **kwargs):
"""
return (
(isinstance(datum, (int, long, numbers.Integral))
- and INT_MIN_VALUE <= datum <= INT_MAX_VALUE)
+ and INT_MIN_VALUE <= datum <= INT_MAX_VALUE
+ and not isinstance(datum, bool))
or isinstance(
datum, (datetime.time, datetime.datetime, datetime.date)
)
@@ -121,7 +122,8 @@ def validate_long(datum, **kwargs):
"""
return (
(isinstance(datum, (int, long, numbers.Integral))
- and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
+ and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE
+ and not isinstance(datum, bool))
or isinstance(
datum, (datetime.time, datetime.datetime, datetime.date)
)
@@ -143,7 +145,10 @@ def validate_float(datum, **kwargs):
kwargs: Any
Unused kwargs
"""
- return isinstance(datum, (int, long, float, numbers.Real))
+ return (
+ isinstance(datum, (int, long, float, numbers.Real))
+ and not isinstance(datum, bool)
+ )
def validate_fixed(datum, schema, **kwargs):

MODIFY
tests/test_validation.py
tests/test_validation.py
@@ -256,10 +256,18 @@ def test_validator_numeric():
("1.0", 'double'),
("1", 'float'),
("1", 'double'),
+ (True, 'int'),
+ (True, 'long'),
+ (True, 'float'),
+ (True, 'double'),
+ (False, 'int'),
+ (False, 'long'),
+ (False, 'float'),
+ (False, 'double'),
]:
with pytest.raises(ValidationError):
validate(datum, schema)
- # and plenty more to add I suppose
+ pytest.fail("{} should not validate as {}".format(datum, schema))
def test_validate_array():

True and False should not validate as int, long, float, and double