From 9252d69ede0b2a086fb7359706d7ef58b41e6561 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 26 May 2022 15:13:09 +0200 Subject: colorscheme: Make use an abstract method The `use` method has always been decorated as being a `@staticmethod`. Many colorschemes use fields to store certain properties, these then need to be accessed using `self`. This isn't possible with a static method so they override it with a regular method. This is fine as far as Python is concerned but PyLint doesn't like the `self` parameters adding an argument to the method. All colorschemes should actually implement the `use` method anyway so making it an `@abstractmethod` seems appropriate and allows us to include the `self` argument. --- ranger/gui/colorscheme.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 859773fb..22ff053f 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -27,6 +27,7 @@ set colorscheme yourschemename from __future__ import (absolute_import, division, print_function) import os.path +from abc import abstractmethod from curses import color_pair from io import open @@ -72,8 +73,8 @@ class ColorScheme(object): fg, bg, attr = self.get(*flatten(keys)) return attr | color_pair(get_color(fg, bg)) - @staticmethod - def use(_): + @abstractmethod + def use(self, context): """Use the colorscheme to determine the (fg, bg, attr) tuple. Override this method in your own colorscheme. -- cgit 1.4.1-2-gfad0 From 4a1fc7eb92f11145e945d69e6dd6a0730b5c17c4 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 26 May 2022 15:22:44 +0200 Subject: accumulator: Make get_list an abstract method Implementations need the `self` parameter and PyLint complains when the number of arguments changes. Since it's never used without reimplementation, `@abstractmethod` is appropriate. --- ranger/ext/accumulator.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ranger/ext/accumulator.py b/ranger/ext/accumulator.py index a41db634..c34370d8 100644 --- a/ranger/ext/accumulator.py +++ b/ranger/ext/accumulator.py @@ -3,6 +3,8 @@ from __future__ import (absolute_import, division, print_function) +from abc import abstractmethod + from ranger.ext.direction import Direction @@ -90,8 +92,8 @@ class Accumulator(object): def sync_index(self, **kw): self.move_to_obj(self.pointed_obj, **kw) - @staticmethod - def get_list(): + @abstractmethod + def get_list(self): """OVERRIDE THIS""" return [] -- cgit 1.4.1-2-gfad0 From 5514b1cf6d5e0fbed8c66e78c2446544325b409b Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 26 May 2022 15:28:44 +0200 Subject: runner: Initialize variables outside of try-except --- ranger/core/runner.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ranger/core/runner.py b/ranger/core/runner.py index 1d2b91f7..c5ec697b 100644 --- a/ranger/core/runner.py +++ b/ranger/core/runner.py @@ -235,9 +235,11 @@ class Runner(object): # pylint: disable=too-few-public-methods if toggle_ui: self._activate_ui(False) + + error = None + process = None + try: - error = None - process = None self.fm.signal_emit('runner.execute.before', popen_kws=popen_kws, context=context) try: -- cgit 1.4.1-2-gfad0 From ff0d4852010bedbd19679c21f3729aeb1770f132 Mon Sep 17 00:00:00 2001 From: toonn Date: Thu, 26 May 2022 15:59:10 +0200 Subject: test_py2_compat: Ignore error message positions --- tests/pylint/test_py2_compat.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/pylint/test_py2_compat.py b/tests/pylint/test_py2_compat.py index 33fc5681..ff13db7c 100644 --- a/tests/pylint/test_py2_compat.py +++ b/tests/pylint/test_py2_compat.py @@ -28,6 +28,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=oldstyle_class, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_classdef(oldstyle_class) @@ -60,6 +61,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=print_function_call, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_call(print_function_call) @@ -100,6 +102,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=early_print_function_call, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_call(early_print_function_call) @@ -117,6 +120,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=implicit_format_spec, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_call(implicit_format_spec) @@ -141,6 +145,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=with_Popen, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_with(with_subprocess_Popen) self.checker.visit_with(with_Popen) @@ -160,6 +165,7 @@ class TestPy2CompatibilityChecker(pylint.testutils.CheckerTestCase): node=f_string, confidence=HIGH, ), + ignore_position=True, ): self.checker.visit_joinedstr(f_string) with self.assertNoMessages(): -- cgit 1.4.1-2-gfad0