From e17dbc7134c4d4ea8561b10dca91ad53a03ebce3 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Thu, 16 May 2019 11:50:38 +0200 Subject: [PATCH] Fixes code smell and ignore some useless (in context) lgtm rules. --- bonobo/__init__.py | 4 ++-- bonobo/_api.py | 7 +++---- bonobo/execution/contexts/base.py | 2 +- bonobo/execution/contexts/node.py | 4 +++- bonobo/util/collections.py | 13 ++++++++++--- bonobo/util/statistics.py | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/bonobo/__init__.py b/bonobo/__init__.py index 2487780..829aa6e 100644 --- a/bonobo/__init__.py +++ b/bonobo/__init__.py @@ -56,8 +56,8 @@ from bonobo._version import __version__ __all__ = ["__version__"] + __all__ with (Path(__file__).parent / "bonobo.svg").open() as f: __logo__ = f.read() -__doc__ = __doc__ -__version__ = __version__ +__doc__ = __doc__ # lgtm [py/redundant-assignment] +__version__ = __version__ # lgtm [py/redundant-assignment] def _repr_html_(): diff --git a/bonobo/_api.py b/bonobo/_api.py index 78ed72f..8432eee 100644 --- a/bonobo/_api.py +++ b/bonobo/_api.py @@ -125,14 +125,13 @@ def open_fs(fs_url=None, *args, **kwargs): :param str default_protocol: The protocol to use if one is not supplied in the FS URL (defaults to ``"osfs"``). :returns: :class:`fs.base.FS` object """ + import os from fs.opener import open_fs as _open_fs - from os.path import expanduser - from os import getcwd if fs_url is None: - fs_url = getcwd() + fs_url = os.getcwd() - return _open_fs(expanduser(str(fs_url)), *args, **kwargs) + return _open_fs(os.path.expanduser(str(fs_url)), *args, **kwargs) # standard transformations diff --git a/bonobo/execution/contexts/base.py b/bonobo/execution/contexts/base.py index 9399d3f..6f3fa71 100644 --- a/bonobo/execution/contexts/base.py +++ b/bonobo/execution/contexts/base.py @@ -74,7 +74,7 @@ class Lifecycle: self.start() return self - def __exit__(self, exc_type=None, exc_val=None, exc_tb=None): + def __exit__(self, exc_type=None, exc_val=None, exc_tb=None): # lgtm [py/special-method-wrong-signature] self.stop() def get_flags_as_string(self): diff --git a/bonobo/execution/contexts/node.py b/bonobo/execution/contexts/node.py index 30b0d5b..2a4294c 100644 --- a/bonobo/execution/contexts/node.py +++ b/bonobo/execution/contexts/node.py @@ -259,7 +259,9 @@ class NodeExecutionContext(BaseContext, WithStatistics): """ for message in messages: if not isinstance(message, Token): - message = ensure_tuple(message, cls=self._input_type, length=self._input_length) + message = ensure_tuple( + message, cls=self._input_type, length=self._input_length + ) # lgtm [py/call/wrong-named-argument] if self._input_length is None: self._input_length = len(message) self.input.put(message) diff --git a/bonobo/util/collections.py b/bonobo/util/collections.py index 9e903ec..bd00954 100644 --- a/bonobo/util/collections.py +++ b/bonobo/util/collections.py @@ -34,6 +34,10 @@ def _with_length_check(f): def tuple_or_const(tuple_or_mixed, *, consts=(None, False), **kwargs): + """ + Like ensure_tuple, but also accept as valid outputs a list of constants. + """ + if tuple_or_mixed in consts: return tuple_or_mixed if isinstance(tuple_or_mixed, str): @@ -49,10 +53,13 @@ def ensure_tuple(tuple_or_mixed, *, cls=None): If it's not a tuple, let's make a tuple of one item. Otherwise, not changed. - :param tuple_or_mixed: - :return: tuple - + :param tuple_or_mixed: material to work on. + :param cls: type of the resulting tuple, or `tuple` if not provided. + :param length: provided by `_with_length_check` decorator, if specified, make sure that the tuple is of this + length (and raise a `TypeError` if not), otherwise, do nothing. + :return: tuple (or something of type `cls`, if provided) """ + if cls is None: cls = tuple diff --git a/bonobo/util/statistics.py b/bonobo/util/statistics.py index 62a5075..23c7ccd 100644 --- a/bonobo/util/statistics.py +++ b/bonobo/util/statistics.py @@ -26,7 +26,7 @@ class Timer: self.__start = time.time() return self - def __exit__(self, type=None, value=None, traceback=None): + def __exit__(self, type=None, value=None, traceback=None): # lgtm [py/special-method-wrong-signature] # Error handling here self.__finish = time.time()