Commit 927604f6 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Remove unnecessary dict lookups

parent d0a03682
......@@ -725,12 +725,10 @@ def get_notification_icon_tooltip_dict():
total_messages)
account['event_lines'].append(text)
else:
for jid in messages:
for jid, msg in messages.items():
text = ngettext('%d message pending',
'%d messages pending',
messages[jid],
messages[jid],
messages[jid])
msg, msg, msg)
contact = app.contacts.get_first_contact_from_jid(
account['name'], jid)
text += ' '
......@@ -753,12 +751,10 @@ def get_notification_icon_tooltip_dict():
total_non_messages)
account['event_lines'].append(text)
else:
for jid in non_messages:
for jid, msg in non_messages.items():
text = ngettext('%d event pending',
'%d events pending',
non_messages[jid],
non_messages[jid],
non_messages[jid])
msg, msg, msg)
text += ' ' + _('from user %s') % (jid)
account[account]['event_lines'].append(text)
......@@ -1268,7 +1264,7 @@ def disconnect_signals(self):
self._callbacks = defaultdict(list)
def disconnect(self, object_):
for signal_name, handlers in self._callbacks.items():
for handlers in self._callbacks.values():
for handler in list(handlers):
func = handler()
if func is None or func.__self__ == object_:
......
......@@ -284,13 +284,13 @@ def _migrate_app_settings(self) -> None:
# Migrate deprecated settings
value = app_settings.pop('send_chatstate_muc_default', None)
if value is not None:
for account in self._account_settings:
self._account_settings[account]['account']['gc_send_chatstate_default'] = value
for account, settings in self._account_settings.items():
settings['account']['gc_send_chatstate_default'] = value
value = app_settings.pop('send_chatstate_default', None)
if value is not None:
for account in self._account_settings:
self._account_settings[account]['account']['send_chatstate_default'] = value
for account, settings in self._account_settings.items():
settings['account']['send_chatstate_default'] = value
value = app_settings.pop('print_join_left_default', None)
if value is not None:
......@@ -664,11 +664,8 @@ def set_group_chat_setting(self,
if default is HAS_ACCOUNT_DEFAULT:
default_store = ACCOUNT_SETTINGS['account']
context_default_setting = f'gc_{setting}_{context}_default'
if context_default_setting in default_store:
default = default_store[context_default_setting]
else:
default = default_store[f'gc_{setting}_default']
default = default_store.get(f'gc_{setting}_{context}_default',
f'gc_{setting}_default')
if not isinstance(value, type(default)) and value is not None:
raise TypeError(f'Invalid type for {setting}: '
......@@ -698,8 +695,8 @@ def set_group_chat_settings(self,
value: SETTING_TYPE,
context: str = None) -> None:
for account in self._account_settings:
for jid in self._account_settings[account]['group_chat']:
for account, acc_settings in self._account_settings.items():
for jid in acc_settings['group_chat']:
if context is not None:
if get_muc_context(jid) != context:
continue
......@@ -776,8 +773,8 @@ def set_contact_settings(self,
setting: str,
value: SETTING_TYPE) -> None:
for account in self._account_settings:
for jid in self._account_settings[account]['contact']:
for account, acc_settings in self._account_settings.items():
for jid in acc_settings['contact']:
self.set_contact_setting(account, jid, setting, value)
def set_soundevent_setting(self,
......
......@@ -251,9 +251,9 @@ def _query_tooltip(self, widget, x_pos, y_pos, keyboard_mode, tooltip):
return False
def del_handlers(self):
for i in self.handlers:
if self.handlers[i].handler_is_connected(i):
self.handlers[i].disconnect(i)
for i, obj in self.handlers.items():
if obj.handler_is_connected(i):
obj.disconnect(i)
del self.handlers
self.tv.destroy()
......
......@@ -170,8 +170,8 @@ def init_list(self):
groups[g] += 1
group_list = []
# Remove special groups if they are empty
for group in groups:
if group not in helpers.special_groups or groups[group] > 0:
for group, c_num in groups.items():
if group not in helpers.special_groups or c_num > 0:
group_list.append(group)
group_list.sort()
for group in group_list:
......
......@@ -1546,8 +1546,8 @@ def create_account(account,
config['custom_type'] = type_.value
app.settings.add_account(account)
for opt in config:
app.settings.set_account_setting(account, opt, config[opt])
for opt, value in config.items():
app.settings.set_account_setting(account, opt, value)
# Password module depends on existing config
passwords.save_password(account, password)
......@@ -1968,8 +1968,8 @@ def run(self, application):
app.plugin_manager.init_plugins()
self.roster._before_fill()
for account in app.connections:
app.connections[account].get_module('Roster').load_roster()
for con in app.connections.values():
con.get_module('Roster').load_roster()
self.roster._after_fill()
# get instances for windows/dialogs that will show_all()/hide()
......
......@@ -2229,8 +2229,8 @@ def prepare_quit(self):
app.settings.set('collapsed_rows', '\t'.join(self.collapsed_rows))
app.interface.save_config()
for account in app.connections:
app.connections[account].quit(True)
for account, con in app.connections.items():
con.quit(True)
self.close_all(account)
if app.interface.systray_enabled:
app.interface.hide_systray()
......@@ -4912,9 +4912,8 @@ def fill_column(self, col):
col.add_attribute(rend[1], rend[3], rend[4])
col.set_cell_data_func(rend[1], rend[5], rend[6])
# set renderers properties
for renderer in self.renderers_propertys:
renderer.set_property(self.renderers_propertys[renderer][0],
self.renderers_propertys[renderer][1])
for renderer, props in self.renderers_propertys.items():
renderer.set_property(props[0], props[1])
def query_tooltip(self, widget, x_pos, y_pos, _keyboard_mode, tooltip):
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment