From 4cd3def507665867f56101d2bb746735a539e9a6 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 3 Jul 2020 14:28:18 +0300 Subject: [PATCH] Fix lint errors and adapt to latest Python --- amodem/__main__.py | 4 ++-- amodem/async_reader.py | 2 +- amodem/calib.py | 3 +-- amodem/common.py | 8 +++++--- amodem/framing.py | 3 +-- amodem/main.py | 2 +- amodem/tests/test_stream.py | 3 ++- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/amodem/__main__.py b/amodem/__main__.py index 28079ac..352c4ab 100644 --- a/amodem/__main__.py +++ b/amodem/__main__.py @@ -236,11 +236,11 @@ def _main(): args.pylab = None if getattr(args, 'plot', False): - import pylab # pylint: disable=import-error + import pylab # pylint: disable=import-error,import-outside-toplevel args.pylab = pylab if args.audio_library == 'ALSA': - from . import alsa + from . import alsa # pylint: disable=import-outside-toplevel interface = alsa.Interface(config) elif args.audio_library == '-': interface = _Dummy() # manually disable PortAudio diff --git a/amodem/async_reader.py b/amodem/async_reader.py index 706e2bb..f392ab0 100644 --- a/amodem/async_reader.py +++ b/amodem/async_reader.py @@ -29,7 +29,7 @@ class AsyncReader: queue.put(buf) total += len(buf) log.debug('AsyncReader thread stopped (read %d bytes)', total) - except BaseException: + except BaseException: # pylint: disable=broad-except log.exception('AsyncReader thread failed') queue.put(None) diff --git a/amodem/calib.py b/amodem/calib.py index ee92a15..4b9f50b 100644 --- a/amodem/calib.py +++ b/amodem/calib.py @@ -107,8 +107,7 @@ def volume_calibration(result_iterator, volume_ctl): def iter_window(iterable, size): # pylint: disable=stop-iteration-return block = [] - while True: - item = next(iterable) + for item in iterable: block.append(item) block = block[-size:] if len(block) == size: diff --git a/amodem/common.py b/amodem/common.py index afdc622..e0e6630 100644 --- a/amodem/common.py +++ b/amodem/common.py @@ -75,10 +75,12 @@ def take(iterable, n): def izip(iterables): """ "Python 3" zip re-implementation for Python 2. """ - # pylint: disable=stop-iteration-return iterables = [iter(iterable) for iterable in iterables] - while True: - yield tuple([next(iterable) for iterable in iterables]) + try: + while True: + yield tuple([next(iterable) for iterable in iterables]) + except StopIteration: + pass class Dummy: diff --git a/amodem/framing.py b/amodem/framing.py index ff4d53c..f510532 100644 --- a/amodem/framing.py +++ b/amodem/framing.py @@ -29,8 +29,7 @@ class Checksum: if received != expected: log.warning('Invalid checksum: %08x != %08x', received, expected) raise ValueError('Invalid checksum') - else: - log.debug('Good checksum: %08x', received) + log.debug('Good checksum: %08x', received) return payload diff --git a/amodem/main.py b/amodem/main.py index cbcab5a..f79b0d4 100644 --- a/amodem/main.py +++ b/amodem/main.py @@ -63,7 +63,7 @@ def recv(config, src, dst, dump_audio=None, pylab=None): freq=freq) receiver.run(sampler, gain=1.0/amplitude, output=dst) return True - except BaseException: + except BaseException: # pylint: disable=broad-except log.exception('Decoding failed') return False finally: diff --git a/amodem/tests/test_stream.py b/amodem/tests/test_stream.py index 848e33c..9f8de83 100644 --- a/amodem/tests/test_stream.py +++ b/amodem/tests/test_stream.py @@ -1,5 +1,6 @@ from amodem import stream import subprocess as sp +import sys script = br""" import sys @@ -14,7 +15,7 @@ while True: def test_read(): - p = sp.Popen(args=['python', '-'], stdin=sp.PIPE, stdout=sp.PIPE) + p = sp.Popen(args=[sys.executable, '-'], stdin=sp.PIPE, stdout=sp.PIPE) p.stdin.write(script) p.stdin.close() f = stream.Reader(p.stdout)