From 5bcd63fe27248bb01fde23b4a364eff00b565080 Mon Sep 17 00:00:00 2001 From: Romain Failliot Date: Sun, 21 Nov 2021 14:15:22 -0500 Subject: [PATCH] pylint: enable import-error, no-name-in-module, no-self-use --- .pylintrc | 3 --- src/diffuse/dialogs.py | 7 +++++-- src/diffuse/main.py | 10 ++++++---- src/diffuse/preferences.py | 4 +++- src/diffuse/utils.py | 1 + src/diffuse/vcs/rcs.py | 6 +++--- src/diffuse/vcs/svk.py | 12 ++++++++---- src/diffuse/vcs/svn.py | 12 ++++++++---- src/diffuse/widgets.py | 7 ++++--- 9 files changed, 38 insertions(+), 24 deletions(-) diff --git a/.pylintrc b/.pylintrc index 3a709f6..c78fdbb 100644 --- a/.pylintrc +++ b/.pylintrc @@ -90,13 +90,10 @@ disable=raw-checker-failed, # temporary silenced messages (ordered alphabetically) duplicate-code, fixme, - import-error, invalid-name, missing-class-docstring, missing-function-docstring, missing-module-docstring, - no-name-in-module, - no-self-use, too-few-public-methods, too-many-arguments, too-many-branches, diff --git a/src/diffuse/dialogs.py b/src/diffuse/dialogs.py index 13f2934..191504f 100644 --- a/src/diffuse/dialogs.py +++ b/src/diffuse/dialogs.py @@ -26,7 +26,9 @@ gi.require_version('Gtk', '3.0') from gi.repository import GObject, Gtk # pylint: enable=wrong-import-position +# pylint: disable-next=no-name-in-module from diffuse import constants + from diffuse import utils # the about dialog @@ -67,7 +69,8 @@ class FileChooserDialog(Gtk.FileChooserDialog): # location for empty panes last_chosen_folder = os.path.realpath(os.curdir) - def __current_folder_changed_cb(self, widget): + @staticmethod + def _current_folder_changed_cb(widget): FileChooserDialog.last_chosen_folder = widget.get_current_folder() def __init__(self, title, parent, prefs, action, accept, rev=False): @@ -96,7 +99,7 @@ class FileChooserDialog(Gtk.FileChooserDialog): self.vbox.pack_start(hbox, False, False, 0) # pylint: disable=no-member hbox.show() self.set_current_folder(self.last_chosen_folder) - self.connect('current-folder-changed', self.__current_folder_changed_cb) + self.connect('current-folder-changed', self._current_folder_changed_cb) def set_encoding(self, encoding): self.encoding.set_text(encoding) diff --git a/src/diffuse/main.py b/src/diffuse/main.py index a2aefdb..995e6df 100644 --- a/src/diffuse/main.py +++ b/src/diffuse/main.py @@ -38,7 +38,9 @@ from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Pango, PangoCairo from urllib.parse import urlparse +# pylint: disable-next=no-name-in-module from diffuse import constants + from diffuse import utils from diffuse.dialogs import AboutDialog, FileChooserDialog, NumericDialog, SearchDialog from diffuse.preferences import Preferences @@ -931,11 +933,11 @@ class Diffuse(Gtk.Window): utils.logDebug(f'Error writing {statepath}.') # select viewer for a newly selected file in the confirm close dialogue - def __confirmClose_row_activated_cb(self, tree, path, col, model): + def _confirmClose_row_activated_cb(self, tree, path, col, model): self.notebook.set_current_page(self.notebook.page_num(model[path][3])) # toggle save state for a file listed in the confirm close dialogue - def __confirmClose_toggle_cb(self, cell, path, model): + def _confirmClose_toggle_cb(self, cell, path, model): model[path][0] = not model[path][0] # returns True if the list of viewers can be closed. The user will be @@ -968,7 +970,7 @@ class Diffuse(Gtk.Window): sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) treeview = Gtk.TreeView.new_with_model(model) r = Gtk.CellRendererToggle.new() - r.connect('toggled', self.__confirmClose_toggle_cb, model) + r.connect('toggled', self._confirmClose_toggle_cb, model) column = Gtk.TreeViewColumn(None, r) column.add_attribute(r, 'active', 0) treeview.append_column(column) @@ -982,7 +984,7 @@ class Diffuse(Gtk.Window): column.set_resizable(True) column.set_sort_column_id(2) treeview.append_column(column) - treeview.connect('row-activated', self.__confirmClose_row_activated_cb, model) + treeview.connect('row-activated', self._confirmClose_row_activated_cb, model) sw.add(treeview) treeview.show() dialog.vbox.pack_start(sw, True, True, 0) # pylint: disable=no-member diff --git a/src/diffuse/preferences.py b/src/diffuse/preferences.py index 197cded..029e6a7 100644 --- a/src/diffuse/preferences.py +++ b/src/diffuse/preferences.py @@ -29,9 +29,11 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk # pylint: enable=wrong-import-position -from diffuse import utils +# pylint: disable-next=no-name-in-module from diffuse import constants +from diffuse import utils + # class to store preferences and construct a dialogue for manipulating them class Preferences: def __init__(self, path): diff --git a/src/diffuse/utils.py b/src/diffuse/utils.py index cbd10bd..e104952 100644 --- a/src/diffuse/utils.py +++ b/src/diffuse/utils.py @@ -29,6 +29,7 @@ gi.require_version('Gtk', '3.0') from gi.repository import Gtk # pylint: enable=wrong-import-position +# pylint: disable-next=no-name-in-module from diffuse import constants # convenience class for displaying a message dialogue diff --git a/src/diffuse/vcs/rcs.py b/src/diffuse/vcs/rcs.py index 710980d..8d8fe01 100644 --- a/src/diffuse/vcs/rcs.py +++ b/src/diffuse/vcs/rcs.py @@ -60,7 +60,7 @@ class Rcs(VcsInterface): return result # simulate use of popen with xargs to read the output of a command - def _popen_xargs_readlines(self, dn, cmd, args, prefs, bash_pref): + def _popen_xargs_readlines(self, cmd, args, prefs, bash_pref): # os.sysconf() is only available on Unix if hasattr(os, 'sysconf'): maxsize = os.sysconf('SC_ARG_MAX') @@ -85,7 +85,7 @@ class Rcs(VcsInterface): s += len(args[i]) + 1 i += 1 if i == len(args) or not f: - ss.extend(utils.popenReadLines(dn, a, prefs, bash_pref)) + ss.extend(utils.popenReadLines(self.root, a, prefs, bash_pref)) s, a = 0, [] return ss @@ -138,7 +138,7 @@ class Rcs(VcsInterface): args = [ utils.safeRelativePath(self.root, k, prefs, 'rcs_cygwin') for k in r ] # run command r, k = {}, '' - for line in self._popen_xargs_readlines(self.root, cmd, args, prefs, 'rcs_bash'): + for line in self._popen_xargs_readlines(cmd, args, prefs, 'rcs_bash'): # parse response if line.startswith('Working file: '): k = prefs.convertToNativePath(line[14:]) diff --git a/src/diffuse/vcs/svk.py b/src/diffuse/vcs/svk.py index 1e021c1..d4add43 100644 --- a/src/diffuse/vcs/svk.py +++ b/src/diffuse/vcs/svk.py @@ -23,18 +23,22 @@ from diffuse import utils from diffuse.vcs.svn import Svn class Svk(Svn): - def _getVcs(self): + @staticmethod + def _getVcs(): return 'svk' - def _getURLPrefix(self): + @staticmethod + def _getURLPrefix(): return 'Depot Path: ' - def _parseStatusLine(self, s): + @staticmethod + def _parseStatusLine(s): if len(s) < 4 or s[0] not in 'ACDMR': return '', '' return s[0], s[4:] - def _getPreviousRevision(self, rev): + @staticmethod + def _getPreviousRevision(rev): if rev is None: return 'HEAD' if rev.endswith('@'): diff --git a/src/diffuse/vcs/svn.py b/src/diffuse/vcs/svn.py index 339d0a5..7aded8b 100644 --- a/src/diffuse/vcs/svn.py +++ b/src/diffuse/vcs/svn.py @@ -31,13 +31,16 @@ class Svn(VcsInterface): VcsInterface.__init__(self, root) self.url = None - def _getVcs(self): + @staticmethod + def _getVcs(): return 'svn' - def _getURLPrefix(self): + @staticmethod + def _getURLPrefix(): return 'URL: ' - def _parseStatusLine(self, s): + @staticmethod + def _parseStatusLine(s): if len(s) < 8 or s[0] not in 'ACDMR': return '', '' # subversion 1.6 adds a new column @@ -46,7 +49,8 @@ class Svn(VcsInterface): k += 1 return s[0], s[k:] - def _getPreviousRevision(self, rev): + @staticmethod + def _getPreviousRevision(rev): if rev is None: return 'BASE' m = int(rev) diff --git a/src/diffuse/widgets.py b/src/diffuse/widgets.py index a655ef4..7a220d7 100644 --- a/src/diffuse/widgets.py +++ b/src/diffuse/widgets.py @@ -1649,7 +1649,8 @@ class FileDiffViewer(Gtk.Grid): # scroll vertically to current line self._ensure_line_is_visible(current_line) - def __set_clipboard_text(self, clipboard, s): + @staticmethod + def _set_clipboard_text(clipboard, s): # remove embedded nulls as the clipboard cannot handle them Gtk.Clipboard.get(clipboard).set_text(s.replace('\0', ''), -1) @@ -1673,7 +1674,7 @@ class FileDiffViewer(Gtk.Grid): self.selection_char = sj if extend: - self.__set_clipboard_text(Gdk.SELECTION_PRIMARY, self.getSelectedText()) + self._set_clipboard_text(Gdk.SELECTION_PRIMARY, self.getSelectedText()) self._cursor_position_changed(True) self.emit('cursor_changed') @@ -2922,7 +2923,7 @@ class FileDiffViewer(Gtk.Grid): # 'copy' action def copy(self): if self.mode in (LINE_MODE, CHAR_MODE): - self.__set_clipboard_text(Gdk.SELECTION_CLIPBOARD, self.getSelectedText()) + self._set_clipboard_text(Gdk.SELECTION_CLIPBOARD, self.getSelectedText()) # 'cut' action def cut(self):