do some linting with flake8

This commit is contained in:
Jan Petykiewicz 2023-01-26 12:40:54 -08:00
parent 0bbc8f8e08
commit 4d362f8e09
6 changed files with 66 additions and 37 deletions

30
.flake8 Normal file
View File

@ -0,0 +1,30 @@
[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,
__init__.py: F401,

View File

@ -28,7 +28,6 @@ T = TypeVar('T', bound='Text')
X = TypeVar('X', bound='Box') X = TypeVar('X', bound='Box')
def read_properties(stream: IO[bytes]) -> Dict[int, bytes]: def read_properties(stream: IO[bytes]) -> Dict[int, bytes]:
""" """
Read element properties. Read element properties.

View File

@ -55,7 +55,7 @@ class FileHeader:
Returns: Returns:
FileHeader object FileHeader object
""" """
version = HEADER.read(stream)[0] _version = HEADER.read(stream)[0] # noqa: F841 # var is unused
mod_time, acc_time = BGNLIB.read(stream) mod_time, acc_time = BGNLIB.read(stream)
name = LIBNAME.skip_and_read(stream) name = LIBNAME.skip_and_read(stream)
uu, dbu = UNITS.skip_and_read(stream) uu, dbu = UNITS.skip_and_read(stream)
@ -223,7 +223,7 @@ def scan_hierarchy(stream: IO[bytes]) -> Dict[bytes, Dict[bytes, int]]:
elif tag == ENDEL.tag: elif tag == ENDEL.tag:
if ref_count is None: if ref_count is None:
ref_count = 1 ref_count = 1
assert(ref_name is not None) assert ref_name is not None
cur_structure[ref_name] += ref_count cur_structure[ref_name] += ref_count
else: else:
stream.seek(size, io.SEEK_CUR) stream.seek(size, io.SEEK_CUR)

View File

@ -12,9 +12,9 @@ from .basic import KlamathError
def test_parse_bitarray(): def test_parse_bitarray():
assert(parse_bitarray(b'59') == 13625) assert parse_bitarray(b'59') == 13625
assert(parse_bitarray(b'\0\0') == 0) assert parse_bitarray(b'\0\0') == 0
assert(parse_bitarray(b'\xff\xff') == 65535) assert parse_bitarray(b'\xff\xff') == 65535
# 4 bytes (too long) # 4 bytes (too long)
with pytest.raises(KlamathError): with pytest.raises(KlamathError):
@ -51,12 +51,12 @@ def test_parse_int4():
def test_decode_real8(): def test_decode_real8():
# zeroes # zeroes
assert(decode_real8(numpy.array([0x0])) == 0) assert decode_real8(numpy.array([0x0])) == 0
assert(decode_real8(numpy.array([1<<63])) == 0) # negative assert decode_real8(numpy.array([1 << 63])) == 0 # negative
assert(decode_real8(numpy.array([0xff << 56])) == 0) # denormalized assert decode_real8(numpy.array([0xff << 56])) == 0 # denormalized
assert(decode_real8(numpy.array([0x4110 << 48])) == 1.0) assert decode_real8(numpy.array([0x4110 << 48])) == 1.0
assert(decode_real8(numpy.array([0xC120 << 48])) == -2.0) assert decode_real8(numpy.array([0xC120 << 48])) == -2.0
def test_parse_real8(): def test_parse_real8():
@ -77,32 +77,32 @@ def test_parse_ascii():
# with pytest.raises(KlamathError): # with pytest.raises(KlamathError):
# parse_ascii(b'') # parse_ascii(b'')
assert(parse_ascii(b'12345') == b'12345') assert parse_ascii(b'12345') == b'12345'
assert(parse_ascii(b'12345\0') == b'12345') # strips trailing null byte assert parse_ascii(b'12345\0') == b'12345' # strips trailing null byte
def test_pack_bitarray(): def test_pack_bitarray():
packed = pack_bitarray(321) packed = pack_bitarray(321)
assert(len(packed) == 2) assert len(packed) == 2
assert(packed == struct.pack('>H', 321)) assert packed == struct.pack('>H', 321)
def test_pack_int2(): def test_pack_int2():
packed = pack_int2((3, 2, 1)) packed = pack_int2((3, 2, 1))
assert(len(packed) == 3*2) assert len(packed) == 3 * 2
assert(packed == struct.pack('>3h', 3, 2, 1)) assert packed == struct.pack('>3h', 3, 2, 1)
assert(pack_int2([-3, 2, -1]) == struct.pack('>3h', -3, 2, -1)) assert pack_int2([-3, 2, -1]) == struct.pack('>3h', -3, 2, -1)
def test_pack_int4(): def test_pack_int4():
packed = pack_int4((3, 2, 1)) packed = pack_int4((3, 2, 1))
assert(len(packed) == 3*4) assert len(packed) == 3 * 4
assert(packed == struct.pack('>3l', 3, 2, 1)) assert packed == struct.pack('>3l', 3, 2, 1)
assert(pack_int4([-3, 2, -1]) == struct.pack('>3l', -3, 2, -1)) assert pack_int4([-3, 2, -1]) == struct.pack('>3l', -3, 2, -1)
def test_encode_real8(): def test_encode_real8():
assert(encode_real8(numpy.array([0.0])) == 0) assert encode_real8(numpy.array([0.0])) == 0
arr = numpy.array((1.0, -2.0, 1e-9, 1e-3, 1e-12)) arr = numpy.array((1.0, -2.0, 1e-9, 1e-3, 1e-12))
assert_array_equal(decode_real8(encode_real8(arr)), arr) assert_array_equal(decode_real8(encode_real8(arr)), arr)
@ -110,10 +110,10 @@ def test_encode_real8():
def test_pack_real8(): def test_pack_real8():
reals = (0, 1, -1, 0.5, 1e-9, 1e-3, 1e-12) reals = (0, 1, -1, 0.5, 1e-9, 1e-3, 1e-12)
packed = pack_real8(reals) packed = pack_real8(reals)
assert(len(packed) == len(reals) * 8) assert len(packed) == len(reals) * 8
assert_array_equal(parse_real8(packed), reals) assert_array_equal(parse_real8(packed), reals)
def test_pack_ascii(): def test_pack_ascii():
assert(pack_ascii(b'4321') == b'4321') assert pack_ascii(b'4321') == b'4321'
assert(pack_ascii(b'321') == b'321\0') assert pack_ascii(b'321') == b'321\0'