diff options
34 files changed, 114 insertions, 129 deletions
diff --git a/examples/plugin_file_filter.py b/examples/plugin_file_filter.py index 27afd551..f5c474c5 100644 --- a/examples/plugin_file_filter.py +++ b/examples/plugin_file_filter.py @@ -19,8 +19,7 @@ HIDE_FILES = ("/boot", "/sbin", "/proc", "/sys") def custom_accept_file(fobj, filters): if not fobj.fm.settings.show_hidden and fobj.path in HIDE_FILES: return False - else: - return ACCEPT_FILE_OLD(fobj, filters) + return ACCEPT_FILE_OLD(fobj, filters) # Overwrite the old function diff --git a/pylintrc b/pylintrc index 935c58f4..d2729ce4 100644 --- a/pylintrc +++ b/pylintrc @@ -8,7 +8,7 @@ max-branches=16 [FORMAT] max-line-length = 99 -disable=locally-disabled,locally-enabled,missing-docstring,duplicate-code,fixme,broad-except,cyclic-import +disable=locally-disabled,locally-enabled,missing-docstring,duplicate-code,fixme,broad-except,cyclic-import,redefined-variable-type [TYPECHECK] ignored-classes=ranger.core.actions.Actions diff --git a/ranger/api/commands.py b/ranger/api/commands.py index 097ead2c..35e073cc 100644 --- a/ranger/api/commands.py +++ b/ranger/api/commands.py @@ -70,7 +70,7 @@ class CommandContainer(object): lst = [cls for cmd, cls in self.commands.items() if cls.allow_abbrev and cmd.startswith(name) or cmd == name] - if len(lst) == 0: + if not lst: raise KeyError if len(lst) == 1: return lst[0] @@ -112,8 +112,7 @@ class Command(FileManagerAware): classdict = cls.__mro__[0].__dict__ if 'name' in classdict and classdict['name']: return cls.name - else: - return cls.__name__ + return cls.__name__ def execute(self): """Override this""" @@ -230,7 +229,7 @@ class Command(FileManagerAware): flags = "" args = self.line.split() rest = "" - if len(args) > 0: + if args: rest = self.line[len(args[0]):].lstrip() for arg in args[1:]: if arg == "--": @@ -283,7 +282,7 @@ class Command(FileManagerAware): dirnames.sort() # no results, return None - if len(dirnames) == 0: + if not dirnames: return # one result. since it must be a directory, append a slash. @@ -347,7 +346,7 @@ class Command(FileManagerAware): pass else: # no results, return None - if len(names) == 0: + if not names: return # one result. append a slash if it's a directory @@ -399,7 +398,7 @@ class FunctionCommand(Command): value = (value == 'True') else: try: - value = float(value) # pylint: disable=redefined-variable-type + value = float(value) except Exception: pass diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py index 9ccb6ff2..7f4c48c5 100644 --- a/ranger/colorschemes/default.py +++ b/ranger/colorschemes/default.py @@ -52,7 +52,7 @@ class Default(ColorScheme): if context.device: attr |= bold if context.link: - fg = context.good and cyan or magenta + fg = cyan if context.good else magenta if context.tag_marker and not context.selected: attr |= bold if fg in (red, magenta): @@ -80,7 +80,7 @@ class Default(ColorScheme): elif context.in_titlebar: attr |= bold if context.hostname: - fg = context.bad and red or green + fg = red if context.bad else green elif context.directory: fg = blue elif context.tab: diff --git a/ranger/colorschemes/solarized.py b/ranger/colorschemes/solarized.py index 0cfcb86d..ad57dd8a 100644 --- a/ranger/colorschemes/solarized.py +++ b/ranger/colorschemes/solarized.py @@ -62,7 +62,7 @@ class Solarized(ColorScheme): bg = 230 attr |= bold if context.link: - fg = context.good and 37 or 160 + fg = 37 if context.good else 160 attr |= bold if context.bad: bg = 235 @@ -93,13 +93,13 @@ class Solarized(ColorScheme): elif context.in_titlebar: attr |= bold if context.hostname: - fg = context.bad and 16 or 255 + fg = 16 if context.bad else 255 if context.bad: bg = 166 elif context.directory: fg = 33 elif context.tab: - fg = context.good and 47 or 33 + fg = 47 if context.good else 33 bg = 239 elif context.link: fg = cyan diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 5fed15ac..1e7ac78c 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -182,7 +182,7 @@ class cd(Command): dirnames = bookmarks + dirnames # no results, return None - if len(dirnames) == 0: + if not dirnames: return # one result. since it must be a directory, append a slash. @@ -236,13 +236,12 @@ class shell(Command): selection = self.fm.thistab.get_selection() if len(selection) == 1: return self.line + selection[0].shell_escaped_basename + ' ' - else: - return self.line + '%s ' - else: - before_word, start_of_word = self.line.rsplit(' ', 1) - return (before_word + ' ' + file.shell_escaped_basename - for file in self.fm.thisdir.files or [] - if file.shell_escaped_basename.startswith(start_of_word)) + return self.line + '%s ' + + before_word, start_of_word = self.line.rsplit(' ', 1) + return (before_word + ' ' + file.shell_escaped_basename + for file in self.fm.thisdir.files or [] + if file.shell_escaped_basename.startswith(start_of_word)) class open_with(Command): @@ -273,10 +272,7 @@ class open_with(Command): mode = 0 split = string.split() - if len(split) == 0: - pass - - elif len(split) == 1: + if len(split) == 1: part = split[0] if self._is_app(part): app = part @@ -964,8 +960,7 @@ class relink(Command): def tab(self, tabnum): if not self.rest(1): return self.line + os.readlink(self.fm.thisfile.path) - else: - return self._tab_directory_content() + return self._tab_directory_content() class help_(Command): @@ -1261,10 +1256,12 @@ class scout(Command): regex = "^(?:(?!%s).)*$" % regex # Compile Regular Expression + # pylint: disable=no-member options = re.UNICODE if self.IGNORE_CASE in flags or self.SMART_CASE in flags and \ pattern.islower(): options |= re.IGNORECASE + # pylint: enable=no-member try: self._regex = re.compile(regex, options) except Exception: @@ -1467,9 +1464,8 @@ class meta(prompt_metadata): metadata = self.fm.metadata.get_metadata(self.fm.thisfile.path) if key in metadata and metadata[key]: return [" ".join([self.arg(0), self.arg(1), metadata[key]])] - else: - return [self.arg(0) + " " + k for k in sorted(metadata) - if k.startswith(self.arg(1))] + return [self.arg(0) + " " + k for k in sorted(metadata) + if k.startswith(self.arg(1))] class linemode(default_linemode): diff --git a/ranger/container/directory.py b/ranger/container/directory.py index 44ca45fe..1fa9065f 100644 --- a/ranger/container/directory.py +++ b/ranger/container/directory.py @@ -217,12 +217,13 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public self._gc_marked_items() if not self.files: return [] + if self.marked_items: return [item for item in self.files if item.marked] elif self.pointed_obj: return [self.pointed_obj] - else: - return [] + + return [] def refilter(self): if self.files_all is None: @@ -360,10 +361,8 @@ class Directory( # pylint: disable=too-many-instance-attributes,too-many-public is_directory=True, ) else: - item = File( # pylint: disable=redefined-variable-type - name, preload=stats, path_is_abs=True, - basename_is_rel_to=basename_is_rel_to - ) + item = File(name, preload=stats, path_is_abs=True, + basename_is_rel_to=basename_is_rel_to) item.load() disk_usage += item.size if self.vcs and self.vcs.track: diff --git a/ranger/container/file.py b/ranger/container/file.py index a746345c..2312761f 100644 --- a/ranger/container/file.py +++ b/ranger/container/file.py @@ -27,7 +27,7 @@ PREVIEW_BLACKLIST = re.compile(r""" # ignore fully numerical file extensions: (\.\d+)*? $ -""", re.VERBOSE | re.IGNORECASE) +""", re.VERBOSE | re.IGNORECASE) # pylint: disable=no-member # Preview these files (almost) always: PREVIEW_WHITELIST = re.compile(r""" @@ -37,7 +37,7 @@ PREVIEW_WHITELIST = re.compile(r""" # ignore filetype-independent suffixes: (\.part|\.bak|~)? $ -""", re.VERBOSE | re.IGNORECASE) +""", re.VERBOSE | re.IGNORECASE) # pylint: disable=no-member class File(FileSystemObject): diff --git a/ranger/container/history.py b/ranger/container/history.py index 857f12b6..5a75854e 100644 --- a/ranger/container/history.py +++ b/ranger/container/history.py @@ -72,7 +72,7 @@ class History(object): """ assert isinstance(other_history, History) - if len(self._history) == 0: + if not self._history: self._index = 0 future_length = 0 else: @@ -81,7 +81,9 @@ class History(object): self._history[:self._index] = list( other_history._history[:other_history._index + 1]) # pylint: disable=protected-access if len(self._history) > self.maxlen: - self._history = self._history[-self.maxlen:] # pylint: disable=protected-access + # pylint: disable=protected-access,invalid-unary-operand-type + self._history = self._history[-self.maxlen:] + # pylint: enable=protected-access,invalid-unary-operand-type self._index = len(self._history) - future_length - 1 assert self._index < len(self._history) @@ -123,7 +125,7 @@ class History(object): def search(self, string, n): if n != 0 and string: - step = n > 0 and 1 or -1 + step = 1 if n > 0 else -1 i = self._index steps_left = steps_left_at_start = int(abs(n)) while steps_left: diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 9bbc777a..acbf9d16 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -174,20 +174,20 @@ class Settings(SignalDispatcher, FileManagerAware): if name in self._localsettings[pattern] and\ regex.search(localpath): return self._localsettings[pattern][name] + if self._tagsettings and path: realpath = os.path.realpath(path) if realpath in self.fm.tags: tag = self.fm.tags.marker(realpath) if tag in self._tagsettings and name in self._tagsettings[tag]: return self._tagsettings[tag][name] - if name in self._settings: - return self._settings[name] - else: + + if name not in self._settings: type_ = self.types_of(name)[0] value = DEFAULT_VALUES[type_] self._raw_set(name, value) self.__setattr__(name, value) - return self._settings[name] + return self._settings[name] def __setattr__(self, name, value): if name.startswith('_'): @@ -198,8 +198,7 @@ class Settings(SignalDispatcher, FileManagerAware): def __getattr__(self, name): if name.startswith('_'): return self.__dict__[name] - else: - return self.get(name, None) + return self.get(name, None) def __iter__(self): for setting in self._settings: @@ -214,8 +213,7 @@ class Settings(SignalDispatcher, FileManagerAware): else: if isinstance(typ, tuple): return typ - else: - return (typ, ) + return (typ,) def _check_type(self, name, value): typ = ALLOWED_SETTINGS[name] @@ -278,8 +276,7 @@ class LocalSettings(object): # pylint: disable=too-few-public-methods def __getattr__(self, name): if name.startswith('_'): return self.__dict__[name] - else: - return self._parent.get(name, self._path) + return self._parent.get(name, self._path) def __iter__(self): for setting in self._parent._settings: # pylint: disable=protected-access diff --git a/ranger/container/tags.py b/ranger/container/tags.py index 2e5623f3..dd13c432 100644 --- a/ranger/container/tags.py +++ b/ranger/container/tags.py @@ -68,8 +68,7 @@ class Tags(object): def marker(self, item): if item in self.tags: return self.tags[item] - else: - return self.default_tag + return self.default_tag def sync(self): try: @@ -133,7 +132,7 @@ class TagsDummy(Tags): def add(self, *items, **others): pass - def remove(self, *items, **others): + def remove(self, *items): pass def toggle(self, *items, **others): diff --git a/ranger/core/actions.py b/ranger/core/actions.py index cd48fc40..1a6b5331 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -614,7 +614,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m elif string in ALLOWED_VALUES: current = self.settings[string] allowed = ALLOWED_VALUES[string] - if len(allowed) > 0: + if allowed: if current not in allowed and current == "": current = allowed[0] if current in allowed: @@ -705,7 +705,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m def search_file(self, text, offset=1, regexp=True): if isinstance(text, str) and regexp: try: - text = re.compile(text, re.U | re.I) + text = re.compile(text, re.UNICODE | re.IGNORECASE) # pylint: disable=no-member except Exception: return False self.thistab.last_search = text @@ -927,10 +927,9 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m if version_info[0] < 3: return os.path.join(ranger.args.cachedir, sha1(path).hexdigest()) + '.jpg' - else: - return os.path.join(ranger.args.cachedir, - sha1(path.encode('utf-8', 'backslashreplace')) - .hexdigest()) + '.jpg' + return os.path.join(ranger.args.cachedir, + sha1(path.encode('utf-8', 'backslashreplace')) + .hexdigest()) + '.jpg' def get_preview(self, fobj, width, height): # pylint: disable=too-many-return-statements pager = self.ui.get_pager() @@ -1181,7 +1180,7 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m self.fm.select_file(file_selection) def _get_tab_list(self): - assert len(self.tabs) > 0, "There must be >=1 tabs at all times" + assert self.tabs, "There must be at least 1 tab at all times" return sorted(self.tabs) # -------------------------- diff --git a/ranger/core/fm.py b/ranger/core/fm.py index a48d77da..0a0be874 100644 --- a/ranger/core/fm.py +++ b/ranger/core/fm.py @@ -113,7 +113,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes if not ranger.args.clean and self.tags is None: self.tags = Tags(self.confpath('tagged')) elif ranger.args.clean: - self.tags = TagsDummy("") # pylint: disable=redefined-variable-type + self.tags = TagsDummy("") if self.bookmarks is None: if ranger.args.clean: @@ -147,7 +147,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes from ranger.ext.shell_escape import shell_quote if self.settings.open_all_images and \ - len(self.thisdir.marked_items) == 0 and \ + not self.thisdir.marked_items and \ re.match(r'^(feh|sxiv|imv|pqiv) ', command): images = [f.relative_path for f in self.thisdir.files if f.image] @@ -228,8 +228,7 @@ class FM(Actions, # pylint: disable=too-many-instance-attributes return URXVTImageDisplayer() elif self.settings.preview_images_method == "urxvt-full": return URXVTImageFSDisplayer() - else: - return ImageDisplayer() + return ImageDisplayer() def _get_thisfile(self): return self.thistab.thisfile diff --git a/ranger/core/linemode.py b/ranger/core/linemode.py index 97c6d4e6..e83dd10c 100644 --- a/ranger/core/linemode.py +++ b/ranger/core/linemode.py @@ -70,8 +70,7 @@ class TitleLinemode(LinemodeBase): name = metadata.title if metadata.year: return "%s - %s" % (metadata.year, name) - else: - return name + return name def infostring(self, fobj, metadata): if metadata.authors: diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 6c4efc36..b4a97394 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -269,8 +269,7 @@ def safeDecode(string): # pylint: disable=invalid-name if HAVE_CHARDET: codec = chardet.detect(string)["encoding"] return string.decode(codec, 'ignore') - else: - return "" + return "" class Loader(FileManagerAware): diff --git a/ranger/core/main.py b/ranger/core/main.py index b5735f3e..b3173da2 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -73,7 +73,7 @@ def main( if len(line) > 2 and line[1] == ':': if line[0] in args.list_tagged_files: sys.stdout.write(line[2:]) - elif len(line) > 0 and '*' in args.list_tagged_files: + elif line and '*' in args.list_tagged_files: sys.stdout.write(line) return 1 if args.fail_unless_cd else 0 # COMPAT diff --git a/ranger/core/metadata.py b/ranger/core/metadata.py index b2a1be3a..238b709d 100644 --- a/ranger/core/metadata.py +++ b/ranger/core/metadata.py @@ -113,20 +113,21 @@ class MetadataManager(object): def _get_metafile_content(self, metafile): import json + if metafile in self.metafile_cache: return self.metafile_cache[metafile] - else: - if exists(metafile): - with open(metafile, "r") as fobj: - try: - entries = json.load(fobj) - except ValueError: - raise ValueError("Failed decoding JSON file %s" % - metafile) - self.metafile_cache[metafile] = entries - return entries - else: - return {} + + if exists(metafile): + with open(metafile, "r") as fobj: + try: + entries = json.load(fobj) + except ValueError: + raise ValueError("Failed decoding JSON file %s" % + metafile) + self.metafile_cache[metafile] = entries + return entries + + return {} def _get_metafile_names(self, path): # Iterates through the paths of all .metadata.json files that could diff --git a/ranger/ext/direction.py b/ranger/ext/direction.py index f4f2c9f9..5d2341c2 100644 --- a/ranger/ext/direction.py +++ b/ranger/ext/direction.py @@ -54,7 +54,7 @@ class Direction(dict): return fallback def up(self): # pylint: disable=invalid-name - return -Direction.down(self) + return -Direction.down(self) # pylint: disable=invalid-unary-operand-type def down(self): return Direction._get_direction(self, 'down', 'up') @@ -66,7 +66,7 @@ class Direction(dict): return Direction._get_bool(self, 'absolute', 'relative') def left(self): - return -Direction.right(self) + return -Direction.right(self) # pylint: disable=invalid-unary-operand-type def relative(self): return not Direction.absolute(self) diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py index e1141409..01f61369 100644 --- a/ranger/ext/img_display.py +++ b/ranger/ext/img_display.py @@ -135,8 +135,7 @@ class W3MImageDisplayer(ImageDisplayer): except IOError as ex: if ex.errno == errno.EPIPE: return - else: - raise ex + raise self.process.stdin.flush() self.process.stdout.readline() @@ -245,16 +244,15 @@ class ITerm2ImageDisplayer(ImageDisplayer, FileManagerAware): max_scale = max(width_scale, height_scale) if width * max_scale <= max_width and height * max_scale <= max_height: return width * max_scale - else: - return width * min_scale - else: - scale = max_height / float(height) - return width * scale + return width * min_scale + + scale = max_height / float(height) + return width * scale elif width > max_width: scale = max_width / float(width) return width * scale - else: - return width + + return width @staticmethod def _encode_image_content(path): diff --git a/ranger/ext/keybinding_parser.py b/ranger/ext/keybinding_parser.py index 7430dfcf..b7816cf3 100644 --- a/ranger/ext/keybinding_parser.py +++ b/ranger/ext/keybinding_parser.py @@ -111,8 +111,8 @@ def parse_keybinding(obj): # pylint: disable=too-many-branches yield int(string) else: yield ord('<') - for char in bracket_content: - yield ord(char) + for bracket_char in bracket_content: + yield ord(bracket_char) yield ord('>') except TypeError: yield keys # it was no tuple, just an int diff --git a/ranger/ext/logutils.py b/ranger/ext/logutils.py index ce77360d..ff27b420 100644 --- a/ranger/ext/logutils.py +++ b/ranger/ext/logutils.py @@ -69,7 +69,7 @@ def setup_logging(debug=True, logfile=None): handlers = [] handlers.append(QueueHandler(log_queue)) if logfile: - if logfile is '-': + if logfile == '-': handlers.append(logging.StreamHandler()) else: handlers.append(logging.FileHandler(logfile)) diff --git a/ranger/ext/openstruct.py b/ranger/ext/openstruct.py index 19d10ebc..7528ee92 100644 --- a/ranger/ext/openstruct.py +++ b/ranger/ext/openstruct.py @@ -24,5 +24,4 @@ class DefaultOpenStruct(collections.defaultdict): def __getattr__(self, name): if name not in self.__dict__: return None - else: - return self.__dict__[name] + return self.__dict__[name] diff --git a/ranger/ext/spawn.py b/ranger/ext/spawn.py index dae532e4..ffb4d94b 100644 --- a/ranger/ext/spawn.py +++ b/ranger/ext/spawn.py @@ -68,5 +68,4 @@ def spawn(*popenargs, **kwargs): """ if len(popenargs) == 1: return check_output(popenargs[0], **kwargs) - else: - return check_output(list(popenargs), **kwargs) + return check_output(list(popenargs), **kwargs) diff --git a/ranger/ext/vcs/bzr.py b/ranger/ext/vcs/bzr.py index 0f0c858d..753b5d05 100644 --- a/ranger/ext/vcs/bzr.py +++ b/ranger/ext/vcs/bzr.py @@ -43,7 +43,9 @@ class Bzr(Vcs): output = self._run(args) except VcsError: return None + # pylint: disable=no-member entries = re.findall(r'-+\n(.+?)\n(?:-|\Z)', output, re.MULTILINE | re.DOTALL) + # pylint: enable=no-member log = [] for entry in entries: diff --git a/ranger/ext/vcs/git.py b/ranger/ext/vcs/git.py index 640d8bfe..c6cb2bf3 100644 --- a/ranger/ext/vcs/git.py +++ b/ranger/ext/vcs/git.py @@ -161,12 +161,13 @@ class Git(Vcs): return 'none' output = self._run(['rev-list', '--left-right', '{0:s}...{1:s}'.format(remote, head)]) + # pylint: disable=no-member ahead = re.search(r'^>', output, flags=re.MULTILINE) behind = re.search(r'^<', output, flags=re.MULTILINE) + # pylint: enable=no-member if ahead: return 'diverged' if behind else 'ahead' - else: - return 'behind' if behind else 'sync' + return 'behind' if behind else 'sync' def data_branch(self): try: diff --git a/ranger/gui/ansi.py b/ranger/gui/ansi.py index 4d6cbeb5..e68e780a 100644 --- a/ranger/gui/ansi.py +++ b/ranger/gui/ansi.py @@ -41,13 +41,13 @@ def text_with_fg_bg_attr(ansi_text): # pylint: disable=too-many-branches,too-ma for x256fg, x256bg, arg in codesplit_re.findall(attr_args + ';'): # first handle xterm256 codes try: - if len(x256fg) > 0: # xterm256 foreground + if x256fg: # xterm256 foreground fg = int(x256fg) continue - elif len(x256bg) > 0: # xterm256 background + elif x256bg: # xterm256 background bg = int(x256bg) continue - elif len(arg) > 0: # usual ansi code + elif arg: # usual ansi code n = int(arg) else: # empty code means reset n = 0 diff --git a/ranger/gui/bar.py b/ranger/gui/bar.py index c1fd6ff9..730b7e27 100644 --- a/ranger/gui/bar.py +++ b/ranger/gui/bar.py @@ -40,7 +40,7 @@ class Bar(object): # remove elemets from the left until it fits if sumsize > wid: - while len(self.left) > 0: + while self.left: leftsize -= len(self.left.pop(-1)) if leftsize + rightsize <= wid: break @@ -48,7 +48,7 @@ class Bar(object): # remove elemets from the right until it fits if sumsize > wid: - while len(self.right) > 0: + while self.right: rightsize -= len(self.right.pop(0)) if leftsize + rightsize <= wid: break @@ -123,7 +123,7 @@ class ColoredString(object): self.string = WideString(string) self.lst = lst self.fixed = False - if not len(string) or not len(self.string.chars): + if not string or not self.string.chars: self.min_size = 0 elif PY3: self.min_size = utf_char_width(string[0]) diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py index 87ba72e4..e077c2eb 100644 --- a/ranger/gui/colorscheme.py +++ b/ranger/gui/colorscheme.py @@ -120,7 +120,7 @@ def _colorscheme_name_to_class(signal): # pylint: disable=too-many-branches if signal.previous and isinstance(signal.previous, ColorScheme): signal.value = signal.previous else: - signal.value = ColorScheme() # pylint: disable=redefined-variable-type + signal.value = ColorScheme() raise Exception("Cannot locate colorscheme `%s'" % scheme_name) else: if usecustom: diff --git a/ranger/gui/mouse_event.py b/ranger/gui/mouse_event.py index b479e383..2fd77a41 100644 --- a/ranger/gui/mouse_event.py +++ b/ranger/gui/mouse_event.py @@ -41,13 +41,12 @@ class MouseEvent(object): # Recently it seems to have been fixed, as 2**21 was introduced as # the code for the "scroll down" button. if self.bstate & curses.BUTTON4_PRESSED: - return self.ctrl() and -self.CTRL_SCROLLWHEEL_MULTIPLIER or -1 + return -self.CTRL_SCROLLWHEEL_MULTIPLIER if self.ctrl() else -1 elif self.bstate & curses.BUTTON2_PRESSED \ or self.bstate & 2**21 \ or self.bstate > curses.ALL_MOUSE_EVENTS: - return self.ctrl() and self.CTRL_SCROLLWHEEL_MULTIPLIER or 1 - else: - return 0 + return self.CTRL_SCROLLWHEEL_MULTIPLIER if self.ctrl() else 1 + return 0 def ctrl(self): return self.bstate & curses.BUTTON_CTRL diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py index 5c665b71..0b171ae6 100644 --- a/ranger/gui/ui.py +++ b/ranger/gui/ui.py @@ -207,7 +207,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method def handle_input(self): key = self.win.getch() - if key is 27 or key >= 128 and key < 256: + if key == 27 or (key >= 128 and key < 256): # Handle special keys like ALT+X or unicode here: keys = [key] previous_load_mode = self.load_mode @@ -436,8 +436,7 @@ class UI( # pylint: disable=too-many-instance-attributes,too-many-public-method def get_pager(self): if hasattr(self.browser, 'pager') and self.browser.pager.visible: return self.browser.pager - else: - return self.pager + return self.pager def _get_viewmode(self): return self._viewmode diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index ae59273b..578c61f8 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -388,8 +388,7 @@ class BrowserColumn(Pager): # pylint: disable=too-many-instance-attributes def _get_index_of_selected_file(self): if self.fm.ui.viewmode == 'multipane' and hasattr(self, 'tab'): return self.tab.pointer - else: - return self.target.pointer + return self.target.pointer @staticmethod def _total_len(predisplay): diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index 349c904f..3c056aa9 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -380,7 +380,8 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- if backward: right_part = self.line[self.pos:] i = self.pos - 2 - while i >= 0 and re.match(r'[\w\d]', self.line[i], re.U): + while i >= 0 and re.match( + r'[\w\d]', self.line[i], re.UNICODE): # pylint: disable=no-member i -= 1 self.copy = self.line[i + 1:self.pos] self.line = self.line[:i + 1] + right_part @@ -388,7 +389,8 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- else: left_part = self.line[:self.pos] i = self.pos + 1 - while i < len(self.line) and re.match(r'[\w\d]', self.line[i], re.U): + while i < len(self.line) and re.match( + r'[\w\d]', self.line[i], re.UNICODE): # pylint: disable=no-member i += 1 self.copy = self.line[self.pos:i] if i >= len(self.line): @@ -457,8 +459,7 @@ class Console(Widget): # pylint: disable=too-many-instance-attributes,too-many- cmd = self._get_cmd() if cmd: return cmd.tab(tabnum) - else: - return None + return None return self.fm.commands.command_generator(self.line) diff --git a/ranger/gui/widgets/pager.py b/ranger/gui/widgets/pager.py index e214b587..4182b189 100644 --- a/ranger/gui/widgets/pager.py +++ b/ranger/gui/widgets/pager.py @@ -198,7 +198,7 @@ class Pager(Widget): # pylint: disable=too-many-instance-attributes return True def click(self, event): - n = event.ctrl() and 1 or 3 + n = 1 if event.ctrl() else 3 direction = event.mouse_wheel_direction() if direction: self.move(down=direction * n) @@ -229,7 +229,7 @@ class Pager(Widget): # pylint: disable=too-many-instance-attributes while True: try: line = self._get_line(i).expandtabs(4) - if self.markup is 'ansi': + if self.markup == 'ansi': line = ansi.char_slice(line, startx, self.wid) + ansi.reset else: line = line[startx:self.wid + startx] diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index 632a1759..e17f131c 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -159,7 +159,7 @@ class StatusBar(Widget): # pylint: disable=too-many-instance-attributes perms = '--%s--' % self.fm.mode.upper() else: perms = target.get_permission_string() - how = getuid() == stat.st_uid and 'good' or 'bad' + how = 'good' if getuid() == stat.st_uid else 'bad' left.add(perms, 'permissions', how) left.add_space() left.add(str(stat.st_nlink), 'nlink') @@ -169,7 +169,7 @@ class StatusBar(Widget): # pylint: disable=too-many-instance-attributes left.add(self._get_group(target), 'group') if target.is_link: - how = target.exists and 'good' or 'bad' + how = 'good' if target.exists else 'bad' try: dest = readlink(target.path) except Exception: @@ -286,7 +286,7 @@ class StatusBar(Widget): # pylint: disable=too-many-instance-attributes # Indicate that there are marked files. Useful if you scroll # away and don't see them anymore. right.add('Mrk', base, 'marked') - elif len(target.files): + elif target.files: right.add(str(target.pointer + 1) + '/' + str(len(target.files)) + ' ', base) if max_pos <= 0: |