From acb0bacc097698bcd782cf6252f3744fd1f6b837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 17 Sep 2018 23:21:38 +0200 Subject: [PATCH] Fix simplifiable-if-statement pylint errors --- gajim/common/app.py | 12 ++++-------- gajim/common/dbus_support.py | 10 ++++------ gajim/common/zeroconf/client_zeroconf.py | 5 +---- gajim/conversation_textview.py | 13 ++++--------- gajim/gtkgui_helpers.py | 5 +---- gajim/tooltips.py | 16 ++++++---------- 6 files changed, 20 insertions(+), 41 deletions(-) diff --git a/gajim/common/app.py b/gajim/common/app.py index 80ccc5d13..3d85e03cd 100644 --- a/gajim/common/app.py +++ b/gajim/common/app.py @@ -424,10 +424,8 @@ def account_supports_private_storage(account): def account_is_connected(account): if account not in connections: return False - if connections[account].connected > 1: # 0 is offline, 1 is connecting - return True - else: - return False + # 0 is offline, 1 is connecting + return connections[account].connected > 1 def is_invisible(account): return SHOW_LIST[connections[account].connected] == 'invisible' @@ -455,11 +453,9 @@ def get_number_of_securely_connected_accounts(): return num_of_secured def account_is_securely_connected(account): - if account_is_connected(account) and \ - account in con_types and con_types[account] in ('tls', 'ssl'): - return True - else: + if not account_is_connected(account): return False + return con_types.get(account) in ('tls', 'ssl') def get_transport_name_from_jid(jid, use_config_setting = True): """ diff --git a/gajim/common/dbus_support.py b/gajim/common/dbus_support.py index 6152598b9..b8d4d26b2 100644 --- a/gajim/common/dbus_support.py +++ b/gajim/common/dbus_support.py @@ -145,16 +145,14 @@ def get_interface(interface, path, start_service=True): started = True if interface not in running_services: # try to start the service - if start_service and dbus_iface.StartServiceByName(interface, dbus.UInt32(0)) == 1: - started = True - else: - started = False + started = start_service and dbus_iface.StartServiceByName( + interface, dbus.UInt32(0)) == 1 if not started: return None obj = bus.get_object(interface, path) return dbus.Interface(obj, interface) - except Exception as e: - log.debug(str(e)) + except Exception as error: + log.debug(error) return None diff --git a/gajim/common/zeroconf/client_zeroconf.py b/gajim/common/zeroconf/client_zeroconf.py index e9e31dd1c..11b0ceead 100644 --- a/gajim/common/zeroconf/client_zeroconf.py +++ b/gajim/common/zeroconf/client_zeroconf.py @@ -598,10 +598,7 @@ class P2PConnection(IdleObject, PlugIn): def _plug_idle(self): readable = self.state != 0 - if self.sendqueue or self.sendbuff: - writable = True - else: - writable = False + writable = self.sendqueue or self.sendbuff if self.writable != writable or self.readable != readable: app.idlequeue.plug_idle(self, writable, readable) diff --git a/gajim/conversation_textview.py b/gajim/conversation_textview.py index 2a719fed0..3cb514b18 100644 --- a/gajim/conversation_textview.py +++ b/gajim/conversation_textview.py @@ -60,10 +60,7 @@ log = logging.getLogger('gajim.conversation_textview') def is_selection_modified(mark): name = mark.get_name() - if name and name in ('selection_bound', 'insert'): - return True - else: - return False + return name in ('selection_bound', 'insert') def has_focus(widget): return widget.get_state_flags() & Gtk.StateFlags.FOCUSED == \ @@ -82,14 +79,12 @@ class TextViewImage(Gtk.Image): def _get_selected(self): parent = self.get_parent() - if not parent or not self.anchor: return False + if not parent or not self.anchor: + return False buffer_ = parent.get_buffer() position = buffer_.get_iter_at_child_anchor(self.anchor) bounds = buffer_.get_selection_bounds() - if bounds and position.in_range(*bounds): - return True - else: - return False + return bounds and position.in_range(*bounds) def get_state(self): parent = self.get_parent() diff --git a/gajim/gtkgui_helpers.py b/gajim/gtkgui_helpers.py index 72fe2f567..869b53982 100644 --- a/gajim/gtkgui_helpers.py +++ b/gajim/gtkgui_helpers.py @@ -266,10 +266,7 @@ def set_unset_urgency_hint(window, unread_messages_no): messages or not """ if app.config.get('use_urgency_hint'): - if unread_messages_no > 0: - window.props.urgency_hint = True - else: - window.props.urgency_hint = False + window.props.urgency_hint = unread_messages_no > 0 def get_pixbuf_from_data(file_data): """ diff --git a/gajim/tooltips.py b/gajim/tooltips.py index f0715a650..b3243e622 100644 --- a/gajim/tooltips.py +++ b/gajim/tooltips.py @@ -139,11 +139,9 @@ class NotificationAreaTooltip(StatusTable): message = acct['message'] message = helpers.reduce_chars_newlines(message, 100, 1) message = GLib.markup_escape_text(message) - if acct['name'] in app.con_types and \ - app.con_types[acct['name']] in ('tls', 'ssl'): - show_lock = True - else: - show_lock = False + con_type = app.con_types.get(acct['name']) + show_lock = con_type in ('tls', 'ssl') + if message: self.add_status_row(file_path, acct['show'], GLib.markup_escape_text(acct['account_label']) + ' - ' + \ @@ -322,11 +320,9 @@ class RosterTooltip(Gtk.Window, StatusTable): message = acct['message'] message = helpers.reduce_chars_newlines(message, 100, 1) message = GLib.markup_escape_text(message) - if acct['name'] in app.con_types and \ - app.con_types[acct['name']] in ('tls', 'ssl'): - show_lock = True - else: - show_lock = False + con_type = app.con_types.get(acct['name']) + show_lock = con_type in ('tls', 'ssl') + if message: self.add_status_row(file_path, acct['show'], GLib.markup_escape_text(acct['account_label']) + ' - ' + \