From 6a1203602f7f7fe8ff5f16b48a8bfbb7191ed5f5 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Mon, 16 Jul 2018 10:00:28 +0200 Subject: [PATCH] Minor tweaks about code quality. --- bonobo/config/configurables.py | 2 +- bonobo/config/services.py | 2 -- bonobo/examples/datasets/__main__.py | 2 +- bonobo/execution/contexts/base.py | 5 ++--- bonobo/execution/strategies/executor.py | 6 +++--- bonobo/nodes/io/csv.py | 3 +-- bonobo/plugins/sentry.py | 1 - bonobo/settings.py | 2 +- bonobo/util/environ.py | 1 - 9 files changed, 9 insertions(+), 15 deletions(-) diff --git a/bonobo/config/configurables.py b/bonobo/config/configurables.py index 20ceca5..98e21e7 100644 --- a/bonobo/config/configurables.py +++ b/bonobo/config/configurables.py @@ -72,7 +72,7 @@ class ConfigurableMeta(type): try: import _functools -except: +except ImportError: import functools PartiallyConfigured = functools.partial diff --git a/bonobo/config/services.py b/bonobo/config/services.py index 282d88f..eae3b8d 100644 --- a/bonobo/config/services.py +++ b/bonobo/config/services.py @@ -1,5 +1,3 @@ -import inspect -import pprint import re import threading import types diff --git a/bonobo/examples/datasets/__main__.py b/bonobo/examples/datasets/__main__.py index 91f702d..a62ce33 100644 --- a/bonobo/examples/datasets/__main__.py +++ b/bonobo/examples/datasets/__main__.py @@ -51,7 +51,7 @@ if __name__ == '__main__': s3.head_object( Bucket='bonobo-examples', Key=s3_path ) - except: + except Exception: s3.upload_file( local_path, 'bonobo-examples', diff --git a/bonobo/execution/contexts/base.py b/bonobo/execution/contexts/base.py index b7f07c5..e071266 100644 --- a/bonobo/execution/contexts/base.py +++ b/bonobo/execution/contexts/base.py @@ -1,7 +1,6 @@ import logging import sys from contextlib import contextmanager -from logging import ERROR from bonobo.util import deprecated from bonobo.util.objects import Wrapper, get_name @@ -13,7 +12,7 @@ def recoverable(error_handler): try: yield except Exception as exc: # pylint: disable=broad-except - error_handler(*sys.exc_info(), level=ERROR) + error_handler(*sys.exc_info(), level=logging.ERROR) @contextmanager @@ -21,7 +20,7 @@ def unrecoverable(error_handler): try: yield except Exception as exc: # pylint: disable=broad-except - error_handler(*sys.exc_info(), level=ERROR) + error_handler(*sys.exc_info(), level=logging.ERROR) raise # raise unrecoverableerror from exc ? diff --git a/bonobo/execution/strategies/executor.py b/bonobo/execution/strategies/executor.py index 1e2d45f..e900ce1 100644 --- a/bonobo/execution/strategies/executor.py +++ b/bonobo/execution/strategies/executor.py @@ -29,7 +29,7 @@ class ExecutorStrategy(Strategy): with self.create_executor() as executor: try: context.start(self.get_starter(executor, futures)) - except: + except Exception: logger.critical('Exception caught while starting execution context.', exc_info=sys.exc_info()) while context.alive: @@ -53,14 +53,14 @@ class ExecutorStrategy(Strategy): try: with node: node.loop() - except: + except Exception: logging.getLogger(__name__).critical( 'Critical error in threadpool node starter.', exc_info=sys.exc_info() ) try: futures.append(executor.submit(_runner)) - except: + except Exception: logging.getLogger(__name__).critical('futures.append', exc_info=sys.exc_info()) return starter diff --git a/bonobo/nodes/io/csv.py b/bonobo/nodes/io/csv.py index d7d03fb..7900dca 100644 --- a/bonobo/nodes/io/csv.py +++ b/bonobo/nodes/io/csv.py @@ -1,12 +1,11 @@ import csv -from bonobo.config import Option, use_raw_input, use_context +from bonobo.config import Option, use_context from bonobo.config.options import Method, RenamedOption from bonobo.constants import NOT_MODIFIED from bonobo.nodes.io.base import FileHandler from bonobo.nodes.io.file import FileReader, FileWriter from bonobo.util import ensure_tuple -from bonobo.util.bags import BagType class CsvHandler(FileHandler): diff --git a/bonobo/plugins/sentry.py b/bonobo/plugins/sentry.py index 44799da..4704c0b 100644 --- a/bonobo/plugins/sentry.py +++ b/bonobo/plugins/sentry.py @@ -1,5 +1,4 @@ from bonobo.plugins import Plugin -from raven import Client class SentryPlugin(Plugin): diff --git a/bonobo/settings.py b/bonobo/settings.py index 799ba3d..d87a329 100644 --- a/bonobo/settings.py +++ b/bonobo/settings.py @@ -52,7 +52,7 @@ class Setting: def set(self, value): value = self.formatter(value) if self.formatter else value if self.validator and not self.validator(value): - raise ValidationError('Invalid value {!r} for setting {}.'.format(value, self.name)) + raise ValidationError(self, 'Invalid value {!r} for setting {!r}.'.format(value, self.name)) self.value = value def set_if_true(self, value): diff --git a/bonobo/util/environ.py b/bonobo/util/environ.py index b344d29..980d1db 100644 --- a/bonobo/util/environ.py +++ b/bonobo/util/environ.py @@ -57,7 +57,6 @@ def get_argument_parser(parser=None): :return: """ if parser is None: - import argparse parser = argparse.ArgumentParser() # Store globally to be able to warn the user about the fact he's probably wrong not to pass a parser to