From 1fa59cbd3073f5824ad43d0923a1ffe75a32d637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Thu, 7 Mar 2024 09:27:20 +0100 Subject: [PATCH] update docs and pylint issues --- README.md | 9 ++++++--- satella/cassandra/common.py | 2 +- satella/coding/expect_exception.py | 3 +-- satella/coding/misc.py | 16 ++++++---------- satella/coding/recast_exceptions.py | 6 ++---- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 7e965e8d..41f6ee63 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ satella ======== -[](https://codeclimate.com/github/piotrmaslanka/satella) +[](https://codeclimate.com/github/piotrmaslanka/satella) [](https://codeclimate.com/github/piotrmaslanka/satella) [](https://pypi.python.org/pypi/satella) [](https://badge.fury.io/py/satella) @@ -18,7 +18,9 @@ Satella uses [semantic versioning 2.0](https://semver.org/spec/v2.0.0.html). Satella contains, among other things: -* things to help you manage your [application's configuration](satella/configuration) +* things to help you manage your [application's configuration](satella/configuration) that allows + you to both load a configuration and specify it's schema using only + Python dictionaries * a fully equipped [metrics library](satella/instrumentation/metrics) * alongside a fully metricized [ThreadPoolExecutor](satella/instrumentation/metrics/structures/threadpool.py) * and an exporter to [Prometheus](satella/instrumentation/metrics/exporters/prometheus.py) or really any @@ -29,7 +31,8 @@ Satella contains, among other things: * [FastAPI](https://github.com/Dronehub/fastapi-satella-metrics) * [Django](https://github.com/piotrmaslanka/django-satella-metrics) * [Flask](https://github.com/piotrmaslanka/flask-satella-metrics) -* helpful [exception handlers](satella/exception_handling) +* helpful [exception handlers](satella/exception_handling) as well as capacity to dump all stack frames + along with their local variables for each thread * monitoring [CPU usage](satella/instrumentation/cpu_time/collectors) on the system and by your own process * common programming [idioms and structures](satella/coding) diff --git a/satella/cassandra/common.py b/satella/cassandra/common.py index 448f63ed..acb3224d 100644 --- a/satella/cassandra/common.py +++ b/satella/cassandra/common.py @@ -1,5 +1,5 @@ try: from cassandra.cluster import ResponseFuture except ImportError: - class ResponseFuture: + class ResponseFuture: # pylint: disable=too-few-public-methods pass diff --git a/satella/coding/expect_exception.py b/satella/coding/expect_exception.py index 0caea5e7..d54ea948 100644 --- a/satella/coding/expect_exception.py +++ b/satella/coding/expect_exception.py @@ -34,8 +34,7 @@ class expect_exception: def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is None: - raise self.else_raise(*self.else_raise_args, - **self.else_raise_kwargs) + raise self.else_raise(*self.else_raise_args, **self.else_raise_kwargs) elif not isinstance(exc_val, self.exc_to_except): return False return True diff --git a/satella/coding/misc.py b/satella/coding/misc.py index 05962dbf..1152e5e1 100644 --- a/satella/coding/misc.py +++ b/satella/coding/misc.py @@ -62,7 +62,7 @@ def contains(needle, haystack) -> bool: class Closeable: """ - A class that needs to clean up it's own resources. + A class that needs to clean up its own resources. It's destructor calls .close(). Use like this: @@ -254,8 +254,7 @@ def update_key_if_true(dictionary: tp.Dict, key: tp.Hashable, value: tp.Any, return dictionary -def get_arguments(function: tp.Callable, *args, **kwargs) -> \ - tp.Dict[str, tp.Any]: +def get_arguments(function: tp.Callable, *args, **kwargs) -> tp.Dict[str, tp.Any]: """ Return local variables that would be defined for given function if called with provided arguments. @@ -273,6 +272,7 @@ def get_arguments(function: tp.Callable, *args, **kwargs) -> \ return _get_arguments(function, False, *args, **kwargs) +# pylint: disable=too-many-locals @rethrow_as(IndexError, TypeError) def _get_arguments(function: tp.Callable, special_behaviour: bool, *args, **kwargs): """ @@ -283,9 +283,7 @@ def _get_arguments(function: tp.Callable, special_behaviour: bool, *args, **kwar local_vars = {} positionals = [param for param in reversed(params) if - param.kind in (Parameter.POSITIONAL_OR_KEYWORD, - Parameter.POSITIONAL_ONLY, - Parameter.VAR_POSITIONAL)] + param.kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.POSITIONAL_ONLY, Parameter.VAR_POSITIONAL)] args = list(reversed(args)) arguments_left = set(param.name for param in params) @@ -303,8 +301,7 @@ def _get_arguments(function: tp.Callable, special_behaviour: bool, *args, **kwar try: if arg.default != Parameter.empty: raise AttributeError() - else: - break + break except (AttributeError, TypeError): v = arg.default local_vars[arg_name] = v @@ -368,8 +365,7 @@ def call_with_arguments(function: tp.Callable, arguments: tp.Dict[str, tp.Any]) continue elif param.default == Parameter.empty: raise TypeError('Argument %s not found' % (param_name,)) - else: - continue + continue if param_kind == Parameter.POSITIONAL_ONLY or param_kind == Parameter.POSITIONAL_OR_KEYWORD: args.append(arguments.pop(param_name)) diff --git a/satella/coding/recast_exceptions.py b/satella/coding/recast_exceptions.py index 3b105ba2..6c1e6e9b 100644 --- a/satella/coding/recast_exceptions.py +++ b/satella/coding/recast_exceptions.py @@ -263,8 +263,7 @@ class rethrow_as: elif self.returns_factory is not None: return self.returns_factory() return - else: - return v + return v return inner @@ -279,8 +278,7 @@ class rethrow_as: self.__exception_remapped.was_raised = True if to is None: return True - else: - raise to(self.exception_preprocessor(exc_val)) + raise to(self.exception_preprocessor(exc_val)) def raises_exception(exc_class: tp.Union[ExceptionClassType, tp.Tuple[ExceptionClassType, ...]], -- GitLab