style fixes (per flake8)

This commit is contained in:
Jan Petykiewicz 2020-10-16 19:00:00 -07:00
parent 4a878aa7bf
commit 60f879a1ad
5 changed files with 82 additions and 44 deletions

29
.flake8 Normal file
View File

@ -0,0 +1,29 @@
[flake8]
ignore =
# E501 line too long
E501,
# W391 newlines at EOF
W391,
# E241 multiple spaces after comma
E241,
# E302 expected 2 newlines
E302,
# W503 line break before binary operator (to be deprecated)
W503,
# E265 block comment should start with '# '
E265,
# E123 closing bracket does not match indentation of opening bracket's line
E123,
# E124 closing bracket does not match visual indentation
E124,
# E221 multiple spaces before operator
E221,
# E201 whitespace after '['
E201,
# E741 ambiguous variable name 'I'
E741,
per-file-ignores =
# F401 import without use
*/__init__.py: F401,

View File

@ -27,10 +27,12 @@
import pathlib
from .main import OasisLayout, Cell, XName
from .basic import NString, AString, Validation, OffsetTable, OffsetEntry, \
EOFError, SignedError, InvalidDataError, InvalidRecordError, \
UnfilledModalError, \
from .basic import (
NString, AString, Validation, OffsetTable, OffsetEntry,
EOFError, SignedError, InvalidDataError, InvalidRecordError,
UnfilledModalError,
ReuseRepetition, GridRepetition, ArbitraryRepetition
)
__author__ = 'Jan Petykiewicz'

View File

@ -13,7 +13,7 @@ import warnings
try:
import numpy
_USE_NUMPY = True
except:
except ImportError:
_USE_NUMPY = False
@ -1491,9 +1491,10 @@ class ArbitraryRepetition:
for x, y in zip(self.x_displacements, self.y_displacements))
return size
def __eq__(self, other: Any) -> bool:
return isinstance(other, type(self)) and self.x_displacements == other.x_displacements and self.y_displacements == other.y_displacements
return (isinstance(other, type(self))
and self.x_displacements == other.x_displacements
and self.y_displacements == other.y_displacements)
def __repr__(self) -> str:
return 'ArbitraryRepetition: x{} y{})'.format(self.x_displacements, self.y_displacements)

View File

@ -9,9 +9,11 @@ import logging
from . import records
from .records import Modals, Record
from .basic import OffsetEntry, OffsetTable, NString, AString, real_t, Validation, \
read_magic_bytes, write_magic_bytes, read_uint, EOFError, \
InvalidDataError, InvalidRecordError
from .basic import (
OffsetEntry, OffsetTable, NString, AString, real_t, Validation,
read_magic_bytes, write_magic_bytes, read_uint, EOFError,
InvalidRecordError,
)
__author__ = 'Jan Petykiewicz'

View File

@ -19,12 +19,14 @@ import io
import logging
import pprint
from warnings import warn
from .basic import AString, NString, repetition_t, property_value_t, real_t, \
ReuseRepetition, OffsetTable, Validation, read_point_list, read_property_value, \
read_bstring, read_uint, read_sint, read_real, read_repetition, read_interval, \
write_bstring, write_uint, write_sint, write_real, write_interval, write_point_list, \
write_property_value, read_bool_byte, write_bool_byte, read_byte, write_byte, \
InvalidDataError, UnfilledModalError, PathExtensionScheme, _USE_NUMPY
from .basic import (
AString, NString, repetition_t, property_value_t, real_t,
ReuseRepetition, OffsetTable, Validation, read_point_list, read_property_value,
read_bstring, read_uint, read_sint, read_real, read_repetition, read_interval,
write_bstring, write_uint, write_sint, write_real, write_interval, write_point_list,
write_property_value, read_bool_byte, write_bool_byte, read_byte, write_byte,
InvalidDataError, UnfilledModalError, PathExtensionScheme, _USE_NUMPY,
)
if _USE_NUMPY:
import numpy
@ -119,6 +121,7 @@ def verify_modal(var: Optional[T]) -> T:
raise UnfilledModalError
return var
'''
Records
@ -487,7 +490,7 @@ class End(Record):
offset_table: Optional[OffsetTable] = OffsetTable.read(stream)
else:
offset_table = None
_padding_string = read_bstring(stream)
_padding_string = read_bstring(stream) # noqa
validation = Validation.read(stream)
record = End(validation, offset_table)
logger.debug('Record ending at 0x{:x}:\n {}'.format(stream.tell(), record))
@ -591,8 +594,8 @@ class CBlock(Record):
if compression_type == 0:
count = len(decompressed_bytes)
compressor = zlib.compressobj(wbits=-zlib.MAX_WBITS, **compression_args)
compressed_bytes = compressor.compress(decompressed_bytes) + \
compressor.flush()
compressed_bytes = (compressor.compress(decompressed_bytes)
+ compressor.flush())
else:
raise InvalidDataError('Unknown compression type: '
'{}'.format(compression_type))
@ -617,8 +620,8 @@ class CBlock(Record):
decompression_args = {}
if self.compression_type == 0:
decompressor = zlib.decompressobj(wbits=-zlib.MAX_WBITS, **decompression_args)
decompressed_bytes = decompressor.decompress(self.compressed_bytes) + \
decompressor.flush()
decompressed_bytes = (decompressor.decompress(self.compressed_bytes)
+ decompressor.flush())
if len(decompressed_bytes) != self.decompressed_byte_count:
raise InvalidDataError('Decompressed data length does not match!')
else:
@ -973,7 +976,7 @@ class Property(Record):
if record_id == 29:
record = Property()
else:
byte = read_byte(stream) #UUUUVCNS
byte = read_byte(stream) # UUUUVCNS
u = 0x0f & (byte >> 4)
v = 0x01 & (byte >> 3)
c = 0x01 & (byte >> 2)
@ -1420,8 +1423,9 @@ class Placement(Record):
r = self.repetition is not None
f = self.flip
if (self.magnification == 1 and
self.angle is not None and abs(self.angle % 90.0) < 1e-14):
if (self.magnification == 1
and self.angle is not None
and abs(self.angle % 90.0) < 1e-14):
aa = int((self.angle / 90) % 4.0)
bools = (c, n, x, y, r, aa & 0b10, aa & 0b01, f)
m = False
@ -2084,11 +2088,11 @@ class Trapezoid(Record, GeometryMixin):
if self.is_vertical:
if height is not None and delta_b - delta_a > height:
raise InvalidDataError('Trapezoid: h < delta_b - delta_a'
' ({} < {} - {})'.format(height, delta_b, delta_a))
+ ' ({} < {} - {})'.format(height, delta_b, delta_a))
else:
if width is not None and delta_b - delta_a > width:
raise InvalidDataError('Trapezoid: w < delta_b - delta_a'
' ({} < {} - {})'.format(width, delta_b, delta_a))
+ ' ({} < {} - {})'.format(width, delta_b, delta_a))
def get_is_vertical(self) -> bool:
return verify_modal(self.is_vertical)
@ -2191,7 +2195,7 @@ class Trapezoid(Record, GeometryMixin):
class CTrapezoid(Record, GeometryMixin):
"""
r"""
CTrapezoid record (ID 26)
Compact trapezoid formats.