diff options
author | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2017-12-17 21:04:30 +0100 |
---|---|---|
committer | Wojciech Siewierski <wojciech.siewierski@onet.pl> | 2017-12-17 21:09:05 +0100 |
commit | 18223912fc4f13a707f1f3fa8f50927e9a0a22a2 (patch) | |
tree | f8b01de23e53542c203773d72d955d0efa3adb0a /ranger | |
parent | 366b1deff7c3deec7fbf8245e23e7d095ea11c14 (diff) | |
download | ranger-18223912fc4f13a707f1f3fa8f50927e9a0a22a2.tar.gz |
Fix the "inconsistent-return-statements" Pylint warning
Some of the changes definitely could have been done better with some refactoring instead of adding a "return" or two. Patches welcome!
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/api/commands.py | 12 | ||||
-rwxr-xr-x | ranger/config/commands.py | 15 | ||||
-rw-r--r-- | ranger/container/directory.py | 1 | ||||
-rw-r--r-- | ranger/core/actions.py | 9 | ||||
-rw-r--r-- | ranger/core/metadata.py | 39 | ||||
-rw-r--r-- | ranger/core/tab.py | 2 | ||||
-rw-r--r-- | ranger/ext/accumulator.py | 4 | ||||
-rw-r--r-- | ranger/ext/next_available_filename.py | 1 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 3 | ||||
-rw-r--r-- | ranger/ext/signals.py | 6 | ||||
-rw-r--r-- | ranger/ext/vcs/vcs.py | 1 | ||||
-rw-r--r-- | ranger/ext/widestring.py | 2 | ||||
-rw-r--r-- | ranger/gui/bar.py | 1 | ||||
-rw-r--r-- | ranger/gui/ui.py | 3 |
14 files changed, 64 insertions, 35 deletions
diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 24a82d0b..9c687927 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -54,8 +54,8 @@ class CommandContainer(FileManagerAware): cmd_cls = self.get_command(cmd_name) if cmd_cls is None: self.fm.notify('alias failed: No such command: {0}'.format(cmd_name), bad=True) - return None - self.commands[name] = _command_init(command_alias_factory(name, cmd_cls, full_command)) + else: + self.commands[name] = _command_init(command_alias_factory(name, cmd_cls, full_command)) def load_commands_from_module(self, module): for var in vars(module).values(): @@ -293,7 +293,7 @@ class Command(FileManagerAware): # no results, return None if not dirnames: - return + return None # one result. since it must be a directory, append a slash. if len(dirnames) == 1: @@ -357,7 +357,7 @@ class Command(FileManagerAware): else: # no results, return None if not names: - return + return None # one result. append a slash if it's a directory if len(names) == 1: @@ -374,7 +374,7 @@ class Command(FileManagerAware): programs = [program for program in get_executables() if program.startswith(self.rest(1))] if not programs: - return + return None if len(programs) == 1: return self.start(1) + programs[0] programs.sort() @@ -397,7 +397,7 @@ def command_function_factory(func): def execute(self): # pylint: disable=too-many-branches if not func: - return + return None if len(self.args) == 1: try: return func(**{'narg': self.quantifier}) diff --git a/ranger/config/commands.py b/ranger/config/commands.py index de3170bb..299f17c2 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -219,6 +219,8 @@ class cd(Command): return matches paths = matches + return None + def _tab_smart(self, dest, dest_abs): tokens = [] basepath = dest_abs @@ -457,6 +459,7 @@ class set_(Command): if name == "colorscheme": return sorted(self.firstpart + colorscheme for colorscheme in get_all_colorschemes(self.fm) if colorscheme.startswith(value)) + return None class setlocal(set_): @@ -785,6 +788,7 @@ class load_copy_buffer(Command): for g in fobj.read().split("\n") if exists(g)) fobj.close() self.fm.ui.redraw_main_column() + return None class save_copy_buffer(Command): @@ -804,6 +808,7 @@ class save_copy_buffer(Command): (fname or self.copy_buffer_filename), bad=True) fobj.write("\n".join(fobj.path for fobj in self.fm.copy_buffer)) fobj.close() + return None class unmark_tag(mark_tag): @@ -925,7 +930,7 @@ class rename(Command): return self.fm.notify('Syntax: rename <newname>', bad=True) if new_name == self.fm.thisfile.relative_path: - return + return None if access(new_name, os.F_OK): return self.fm.notify("Can't rename: file already exists!", bad=True) @@ -937,6 +942,8 @@ class rename(Command): self.fm.thisdir.pointed_obj = file_new self.fm.thisfile = file_new + return None + def tab(self, tabnum): return self._tab_directory_content() @@ -1118,7 +1125,7 @@ class relink(Command): return self.fm.notify('%s is not a symlink!' % tfile.relative_path, bad=True) if new_path == os.readlink(tfile.path): - return + return None try: os.remove(tfile.path) @@ -1130,6 +1137,8 @@ class relink(Command): self.fm.thisdir.pointed_obj = tfile self.fm.thisfile = tfile + return None + def tab(self, tabnum): if not self.rest(1): return self.line + os.readlink(self.fm.thisfile.path) @@ -1177,6 +1186,8 @@ class copymap(Command): for arg in self.args[2:]: self.fm.ui.keymaps.copy(self.context, self.arg(1), arg) + return None + class copypmap(copymap): """:copypmap <keys> <newkeys1> [<newkeys2>...] diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 8ca533d7..18b1687c 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -179,6 +179,7 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public self._vcs_signal_handler_installed = True if self.settings.vcs_aware: return Vcs(self) + return None def signal_function_factory(self, function): def signal_function(): diff --git a/ranger/core/actions.py b/ranger/core/actions.py index e875aca3..0298af19 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -229,7 +229,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m cmd_class = self.commands.get_command(command_name) if cmd_class is None: self.notify("Command not found: `%s'" % command_name, bad=True) - return + return None cmd = cmd_class(string, quantifier=quantifier) if cmd.resolve_macros and _MacroTemplate.delimiter in cmd.line: @@ -252,6 +252,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if ranger.args.debug: raise self.notify(ex) + return None def substitute_macros(self, string, # pylint: disable=redefined-outer-name additional=None, escape=False): @@ -739,6 +740,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m # -- Searching # -------------------------- + # TODO: Do we still use this method? Should we remove it? def search_file(self, text, offset=1, regexp=True): if isinstance(text, str) and regexp: try: @@ -747,6 +749,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m return False self.thistab.last_search = text self.search_next(order='search', offset=offset) + return None def search_next(self, order=None, offset=1, forward=True): original_order = order @@ -797,6 +800,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m return cwd.cycle(forward=None) return cwd.cycle(forward=forward) + return None def set_search_method(self, order, forward=True): # pylint: disable=unused-argument if order in ('search', 'tag', 'size', 'mimetype', 'ctime', 'mtime', 'atime'): @@ -1084,6 +1088,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m else: pager.set_source(self.thisfile.get_preview_source( pager.wid, pager.hei)) + return None def on_destroy(signal): # pylint: disable=unused-argument try: @@ -1174,6 +1179,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m newtab = tablist[(current_index + offset) % len(tablist)] if newtab != self.current_tab: self.tab_open(newtab) + return None def tab_new(self, path=None, narg=None): if narg: @@ -1181,6 +1187,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m for i in range(1, 10): if i not in self.tabs: return self.tab_open(i, path) + return None def tab_switch(self, path, create_directory=False): """Switches to tab of given path, opening a new tab as necessary. diff --git a/ranger/core/metadata.py b/ranger/core/metadata.py index 28b1f5b7..75f7ba3c 100644 --- a/ranger/core/metadata.py +++ b/ranger/core/metadata.py @@ -90,26 +90,25 @@ class MetadataManager(object): def _get_entry(self, filename): if filename in self.metadata_cache: return self.metadata_cache[filename] - else: - - # Try to find an entry for this file in any of - # the applicable .metadata.json files - for metafile in self._get_metafile_names(filename): - entries = self._get_metafile_content(metafile) - # Check for a direct match: - if filename in entries: - entry = entries[filename] - # Check for a match of the base name: - elif basename(filename) in entries: - entry = entries[basename(filename)] - else: - # No match found, try another entry - continue - - self.metadata_cache[filename] = entry - return entry - - raise KeyError + + # Try to find an entry for this file in any of + # the applicable .metadata.json files + for metafile in self._get_metafile_names(filename): + entries = self._get_metafile_content(metafile) + # Check for a direct match: + if filename in entries: + entry = entries[filename] + # Check for a match of the base name: + elif basename(filename) in entries: + entry = entries[basename(filename)] + else: + # No match found, try another entry + continue + + self.metadata_cache[filename] = entry + return entry + + raise KeyError def _get_metafile_content(self, metafile): import json diff --git a/ranger/core/tab.py b/ranger/core/tab.py index 160f590f..1d5e69d4 100644 --- a/ranger/core/tab.py +++ b/ranger/core/tab.py @@ -111,7 +111,7 @@ class Tab(FileManagerAware, SettingsAware): # pylint: disable=too-many-instance """Enter given path""" # TODO: Ensure that there is always a self.thisdir if path is None: - return + return None path = str(path) # clear filter in the folder we're leaving diff --git a/ranger/ext/accumulator.py b/ranger/ext/accumulator.py index b0e4a1c5..c2e33b59 100644 --- a/ranger/ext/accumulator.py +++ b/ranger/ext/accumulator.py @@ -29,12 +29,12 @@ class Accumulator(object): def move_to_obj(self, arg, attr=None): if not arg: - return + return None lst = self.get_list() if not lst: - return + return None do_get_attr = isinstance(attr, str) diff --git a/ranger/ext/next_available_filename.py b/ranger/ext/next_available_filename.py index 91d48631..0a5e0856 100644 --- a/ranger/ext/next_available_filename.py +++ b/ranger/ext/next_available_filename.py @@ -19,3 +19,4 @@ def next_available_filename(fname, directory="."): for i in range(1, len(existing_files) + 1): if fname + str(i) not in existing_files: return fname + str(i) + return None diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index cfb07f5f..023ff1ba 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -244,6 +244,7 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes return bool(os.environ.get(argument)) elif function == 'else': return True + return None def get_mimetype(self, fname): # Spawn "file" to determine the mime-type of the given file. @@ -379,6 +380,8 @@ class Rifle(object): # pylint: disable=too-many-instance-attributes finally: self.hook_after_executing(command, self._mimetype, self._app_flags) + return None + def find_conf_path(): # Find configuration file path diff --git a/ranger/ext/signals.py b/ranger/ext/signals.py index cbd35643..67c8960d 100644 --- a/ranger/ext/signals.py +++ b/ranger/ext/signals.py @@ -155,6 +155,7 @@ class SignalDispatcher(object): key=lambda handler: -handler.priority) return handler + # TODO: Do we still use this method? Should we remove it? def signal_force_sort(self, signal_name=None): """Forces a sorting of signal handlers by priority. @@ -165,11 +166,12 @@ class SignalDispatcher(object): for handlers in self._signals.values(): handlers.sort( key=lambda handler: -handler.priority) + return None elif signal_name in self._signals: self._signals[signal_name].sort( key=lambda handler: -handler.priority) - else: - return False + return None + return False def signal_unbind(self, signal_handler): """Removes a signal binding. diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index ba28d141..1d0edff4 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -125,6 +125,7 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes else: with open(os.devnull, mode='w') as fd_devnull: subprocess.check_call(cmd, cwd=path, stdout=fd_devnull, stderr=fd_devnull) + return None except (subprocess.CalledProcessError, OSError): raise VcsError('{0:s}: {1:s}'.format(str(cmd), path)) diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py index 0153c16c..2721643c 100644 --- a/ranger/ext/widestring.py +++ b/ranger/ext/widestring.py @@ -81,6 +81,7 @@ class WideString(object): # pylint: disable=too-few-public-methods return WideString(self.string + string) elif isinstance(string, WideString): return WideString(self.string + string.string, self.chars + string.chars) + return None def __radd__(self, string): """ @@ -91,6 +92,7 @@ class WideString(object): # pylint: disable=too-few-public-methods return WideString(string + self.string) elif isinstance(string, WideString): return WideString(string.string + self.string, string.chars + self.chars) + return None def __str__(self): return self.string diff --git a/ranger/gui/bar.py b/ranger/gui/bar.py index 64bd6ce1..3f4b891c 100644 --- a/ranger/gui/bar.py +++ b/ranger/gui/bar.py @@ -77,6 +77,7 @@ class Bar(object): else: item.cut_off(oversize) break + return None def fill_gap(self, char, wid, gapwidth=False): del self.gap[:] diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 5877e484..990db0ad 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -509,6 +509,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method if viewmode == 'miller': from ranger.gui.widgets.view_miller import ViewMiller return ViewMiller - if viewmode == 'multipane': + elif viewmode == 'multipane': from ranger.gui.widgets.view_multipane import ViewMultipane return ViewMultipane + return None |