fixes for new version of flake8
MODIFY
.flake8.cython
.flake8.cython
[flake8]
filename = *.pyx
-ignore = E999,E225
+ignore = E999,E225,W503
max-line-length = 90

MODIFY
fastavro/_read.pyx
fastavro/_read.pyx
@@ -254,10 +254,10 @@ cdef read_float(fo, writer_schema=None, reader_schema=None):
data = fo.read(4)
if len(data) == 4:
ch_data[:4] = data
- fi.n = (ch_data[0] |
- (ch_data[1] << 8) |
- (ch_data[2] << 16) |
- (ch_data[3] << 24))
+ fi.n = (ch_data[0]
+ | (ch_data[1] << 8)
+ | (ch_data[2] << 16)
+ | (ch_data[3] << 24))
return fi.f
else:
raise ReadError
@@ -280,14 +280,14 @@ cdef read_double(fo, writer_schema=None, reader_schema=None):
data = fo.read(8)
if len(data) == 8:
ch_data[:8] = data
- dl.n = (ch_data[0] |
- (<ulong64>(ch_data[1]) << 8) |
- (<ulong64>(ch_data[2]) << 16) |
- (<ulong64>(ch_data[3]) << 24) |
- (<ulong64>(ch_data[4]) << 32) |
- (<ulong64>(ch_data[5]) << 40) |
- (<ulong64>(ch_data[6]) << 48) |
- (<ulong64>(ch_data[7]) << 56))
+ dl.n = (ch_data[0]
+ | (<ulong64>(ch_data[1]) << 8)
+ | (<ulong64>(ch_data[2]) << 16)
+ | (<ulong64>(ch_data[3]) << 24)
+ | (<ulong64>(ch_data[4]) << 32)
+ | (<ulong64>(ch_data[5]) << 40)
+ | (<ulong64>(ch_data[6]) << 48)
+ | (<ulong64>(ch_data[7]) << 56))
return dl.d
else:
raise ReadError

MODIFY
fastavro/_read_py.py
fastavro/_read_py.py
@@ -631,7 +631,7 @@ class file_reader:
def __iter__(self):
if not self._elems:
- raise NotImplemented
+ raise NotImplementedError
return self._elems
def next(self):

MODIFY
fastavro/_schema.pyx
fastavro/_schema.pyx
@@ -37,8 +37,8 @@ cpdef schema_name(schema, parent_ns):
name = schema['name']
except KeyError:
msg = (
- '"name" is a required field missing from ' +
- 'the schema: {}'.format(schema)
+ '"name" is a required field missing from '
+ + 'the schema: {}'.format(schema)
)
raise SchemaParseException(msg)
@@ -91,14 +91,14 @@ cdef _parse_schema(schema, namespace, _write_hint):
scale = parsed_schema.get("scale")
if scale and not isinstance(scale, int):
raise SchemaParseException(
- "decimal scale must be a postive integer, " +
- "not {}".format(scale)
+ "decimal scale must be a postive integer, "
+ + "not {}".format(scale)
)
precision = parsed_schema.get("precision")
if precision and not isinstance(precision, int):
raise SchemaParseException(
- "decimal precision must be a postive integer, " +
- "not {}".format(precision)
+ "decimal precision must be a postive integer, "
+ + "not {}".format(precision)
)
if schema_type == "array":

MODIFY
fastavro/_schema_py.py
fastavro/_schema_py.py
@@ -38,8 +38,8 @@ def schema_name(schema, parent_ns):
name = schema['name']
except KeyError:
msg = (
- '"name" is a required field missing from ' +
- 'the schema: {}'.format(schema)
+ '"name" is a required field missing from '
+ + 'the schema: {}'.format(schema)
)
raise SchemaParseException(msg)
@@ -116,14 +116,14 @@ def _parse_schema(schema, namespace, _write_hint):
scale = parsed_schema.get("scale")
if scale and not isinstance(scale, int):
raise SchemaParseException(
- "decimal scale must be a postive integer, " +
- "not {}".format(scale)
+ "decimal scale must be a postive integer, "
+ + "not {}".format(scale)
)
precision = parsed_schema.get("precision")
if precision and not isinstance(precision, int):
raise SchemaParseException(
- "decimal precision must be a postive integer, " +
- "not {}".format(precision)
+ "decimal precision must be a postive integer, "
+ + "not {}".format(precision)
)
if schema_type == "array":

MODIFY
fastavro/_six.pyx
fastavro/_six.pyx
@@ -15,6 +15,7 @@ _encoding = 'UTF-8'
if sys.version_info >= (3, 0):
from io import BytesIO as MemoryIO
xrange = range
+
def py3_btou(n, encoding=_encoding):
return n.decode(encoding)
@@ -51,18 +52,18 @@ if sys.version_info >= (3, 0):
return True
else:
raise ValueError(
- "When appending to an avro file you must use the " +
- "'a+' mode, not just 'a'"
+ "When appending to an avro file you must use the "
+ + "'a+' mode, not just 'a'"
)
else:
return False
else: # Python 2x
- from cStringIO import StringIO as MemoryIO # flake8: noqa
+ from cStringIO import StringIO as MemoryIO # noqa
xrange = xrange
def py2_btou(n, encoding=_encoding):
- return unicode(n, encoding) # flake8: noqa
+ return unicode(n, encoding) # noqa
def py2_utob(n, encoding=_encoding):
return n.encode(encoding)
@@ -85,7 +86,7 @@ else: # Python 2x
return obj.iteritems()
def py2_is_str(obj):
- return isinstance(obj, basestring) # flake8: noqa
+ return isinstance(obj, basestring) # noqa
def py2_mk_bits(bits):
return chr(bits & 0xff)
@@ -108,7 +109,7 @@ else: # Python 2x
# the mode. If that doesn't exist (like in the case of an io.BytesIO)
# then we check the position and readablility.
try:
- mode = file_like.mode
+ file_like.mode
except AttributeError:
# This is probably some io stream so we rely on its tell() working
if file_like.tell() != 0 and _readable(file_like):
@@ -121,8 +122,8 @@ else: # Python 2x
return True
else:
raise ValueError(
- "When appending to an avro file you must use the " +
- "'a+' mode, not just 'a'"
+ "When appending to an avro file you must use the "
+ + "'a+' mode, not just 'a'"
)
else:
return False

MODIFY
fastavro/_validation.pyx
fastavro/_validation.pyx
@@ -45,9 +45,9 @@ cdef inline bint validate_bytes(datum, schema=None,
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) or
- isinstance(datum, (
+ (isinstance(datum, (int, long, numbers.Integral))
+ and INT_MIN_VALUE <= datum <= INT_MAX_VALUE)
+ or isinstance(datum, (
datetime.time, datetime.datetime, datetime.date))
)
@@ -55,10 +55,9 @@ cdef inline bint validate_int(datum, schema=None,
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) or
- isinstance(datum, (
- datetime.time, datetime.datetime, datetime.date))
+ (isinstance(datum, (int, long, numbers.Integral))
+ and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
+ or isinstance(datum, (datetime.time, datetime.datetime, datetime.date))
)
@@ -69,9 +68,10 @@ cdef inline bint validate_float(datum, schema=None,
cdef inline bint validate_fixed(datum, dict schema,
str parent_ns='', bint raise_errors=True):
- return (isinstance(datum, bytes) and
- len(datum) == schema['size']) or \
- (isinstance(datum, decimal.Decimal))
+ return (
+ (isinstance(datum, bytes) and len(datum) == schema['size'])
+ or isinstance(datum, decimal.Decimal)
+ )
cdef inline bint validate_enum(datum, dict schema,

MODIFY
fastavro/_validation_py.py
fastavro/_validation_py.py
@@ -91,10 +91,11 @@ def validate_int(datum, **kwargs):
Unused kwargs
"""
return (
- (isinstance(datum, (int, long, numbers.Integral)) and
- INT_MIN_VALUE <= datum <= INT_MAX_VALUE) or
- isinstance(datum, (datetime.time, datetime.datetime,
- datetime.date))
+ (isinstance(datum, (int, long, numbers.Integral))
+ and INT_MIN_VALUE <= datum <= INT_MAX_VALUE)
+ or isinstance(
+ datum, (datetime.time, datetime.datetime, datetime.date)
+ )
)
@@ -118,10 +119,11 @@ def validate_long(datum, **kwargs):
Unused kwargs
"""
return (
- (isinstance(datum, (int, long, numbers.Integral)) and
- LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE) or
- isinstance(datum, (datetime.time, datetime.datetime,
- datetime.date))
+ (isinstance(datum, (int, long, numbers.Integral))
+ and LONG_MIN_VALUE <= datum <= LONG_MAX_VALUE)
+ or isinstance(
+ datum, (datetime.time, datetime.datetime, datetime.date)
+ )
)

MODIFY
fastavro/_write.pyx
fastavro/_write.pyx
@@ -127,16 +127,16 @@ cpdef prepare_uuid(object data, schema):
cpdef prepare_time_millis(object data, schema):
if isinstance(data, datetime.time):
return int(
- data.hour * MLS_PER_HOUR + data.minute * MLS_PER_MINUTE +
- data.second * MLS_PER_SECOND + int(data.microsecond / 1000))
+ data.hour * MLS_PER_HOUR + data.minute * MLS_PER_MINUTE
+ + data.second * MLS_PER_SECOND + int(data.microsecond / 1000))
else:
return data
cpdef prepare_time_micros(object data, schema):
if isinstance(data, datetime.time):
- return long(data.hour * MCS_PER_HOUR + data.minute * MCS_PER_MINUTE +
- data.second * MCS_PER_SECOND + data.microsecond)
+ return long(data.hour * MCS_PER_HOUR + data.minute * MCS_PER_MINUTE
+ + data.second * MCS_PER_SECOND + data.microsecond)
else:
return data

MODIFY
fastavro/_write_py.py
fastavro/_write_py.py
@@ -89,8 +89,8 @@ def prepare_time_millis(data, schema):
"""Convert datetime.time to int timestamp with milliseconds"""
if isinstance(data, datetime.time):
return int(
- data.hour * MLS_PER_HOUR + data.minute * MLS_PER_MINUTE +
- data.second * MLS_PER_SECOND + int(data.microsecond / 1000))
+ data.hour * MLS_PER_HOUR + data.minute * MLS_PER_MINUTE
+ + data.second * MLS_PER_SECOND + int(data.microsecond / 1000))
else:
return data
@@ -98,8 +98,8 @@ def prepare_time_millis(data, schema):
def prepare_time_micros(data, schema):
"""Convert datetime.time to int timestamp with microseconds"""
if isinstance(data, datetime.time):
- return long(data.hour * MCS_PER_HOUR + data.minute * MCS_PER_MINUTE +
- data.second * MCS_PER_SECOND + data.microsecond)
+ return long(data.hour * MCS_PER_HOUR + data.minute * MCS_PER_MINUTE
+ + data.second * MCS_PER_SECOND + data.microsecond)
else:
return data

MODIFY
fastavro/read.py
fastavro/read.py
try:
from . import _read
-except ImportError as e:
+except ImportError:
from . import _read_py as _read
from . import _read_common

MODIFY
fastavro/six.py
fastavro/six.py
@@ -15,6 +15,7 @@ _encoding = 'UTF-8'
if sys.version_info >= (3, 0):
from io import BytesIO as MemoryIO
xrange = range
+
def py3_btou(n, encoding=_encoding):
return n.decode(encoding)
@@ -51,18 +52,18 @@ if sys.version_info >= (3, 0):
return True
else:
raise ValueError(
- "When appending to an avro file you must use the " +
- "'a+' mode, not just 'a'"
+ "When appending to an avro file you must use the "
+ + "'a+' mode, not just 'a'"
)
else:
return False
else: # Python 2x
- from cStringIO import StringIO as MemoryIO # flake8: noqa
+ from cStringIO import StringIO as MemoryIO # noqa
xrange = xrange
def py2_btou(n, encoding=_encoding):
- return unicode(n, encoding) # flake8: noqa
+ return unicode(n, encoding) # noqa
def py2_utob(n, encoding=_encoding):
return n.encode(encoding)
@@ -85,7 +86,7 @@ else: # Python 2x
return obj.iteritems()
def py2_is_str(obj):
- return isinstance(obj, basestring) # flake8: noqa
+ return isinstance(obj, basestring) # noqa
def py2_mk_bits(bits):
return chr(bits & 0xff)
@@ -108,7 +109,7 @@ else: # Python 2x
# the mode. If that doesn't exist (like in the case of an io.BytesIO)
# then we check the position and readablility.
try:
- mode = file_like.mode
+ file_like.mode
except AttributeError:
# This is probably some io stream so we rely on its tell() working
if file_like.tell() != 0 and _readable(file_like):
@@ -121,8 +122,8 @@ else: # Python 2x
return True
else:
raise ValueError(
- "When appending to an avro file you must use the " +
- "'a+' mode, not just 'a'"
+ "When appending to an avro file you must use the "
+ + "'a+' mode, not just 'a'"
)
else:
return False

MODIFY
fastavro/write.py
fastavro/write.py
try:
from . import _write
-except ImportError as e:
+except ImportError:
from . import _write_py as _write
# Private API

fixes for new version of flake8