Skip to content

Commit

Permalink
[Lint] Fix ruff lint gettext and type comparison
Browse files Browse the repository at this point in the history
The gettext strings cannot be formatted until after the function return
from gettext.

Refs: https://docs.astral.sh/ruff/rules/f-string-in-get-text-func-call/
Refs: https://docs.astral.sh/ruff/rules/printf-in-get-text-func-call/
  • Loading branch information
cas-- committed Sep 8, 2024
1 parent e7d08d7 commit 2247668
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions deluge/plugins/Blocklist/deluge_blocklist/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ def parse(cls, ip):
try:
q1, q2, q3, q4 = (int(q) for q in ip.split('.'))
except ValueError:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
if q1 < 0 or q2 < 0 or q3 < 0 or q4 < 0:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
elif q1 > 255 or q2 > 255 or q3 > 255 or q4 > 255:
raise BadIP(_('The IP address "%s" is badly formed' % ip))
raise BadIP(_('The IP address "%s" is badly formed') % ip)
return cls(q1, q2, q3, q4)

def quadrants(self):
Expand Down
2 changes: 1 addition & 1 deletion deluge/tests/test_json_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestJSON:
async def test_get_remote_methods(self):
json = JSON()
methods = await json.get_remote_methods()
assert type(methods) == tuple
assert isinstance(methods, tuple)
assert len(methods) > 0

def test_render_fail_disconnected(self):
Expand Down
2 changes: 1 addition & 1 deletion deluge/tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_old_log_deprecation_warning(self):
# Cause all warnings to always be triggered.
warnings.simplefilter('always')
LOG.debug('foo')
assert w[-1].category == DeprecationWarning
assert w[-1].category is DeprecationWarning

# def test_twisted_error_log(self):
# from twisted.internet import defer
Expand Down
2 changes: 1 addition & 1 deletion deluge/tests/test_ui_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def set_up(self):
return UIWithDaemonBaseTestCase.set_up(self)

def patch_arg_command(self, command):
if type(command) == str:
if isinstance(command, str):
command = [command]
username, password = get_localhost_auth()
self.patch(
Expand Down
2 changes: 1 addition & 1 deletion deluge/tests/test_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_connect(self, client):
d = self.deluge_web.web_api.connect(self.host_id)

def on_connect(result):
assert type(result) == tuple
assert isinstance(result, tuple)
assert len(result) > 0
return result

Expand Down
2 changes: 1 addition & 1 deletion deluge/ui/console/cmdline/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def add_subparser(self, subparsers):
for cmd_name in sorted([self.name] + self.aliases):
if cmd_name not in subparsers._name_parser_map:
if cmd_name in self.aliases:
opts['help'] = _('`%s` alias' % self.name)
opts['help'] = _('`%s` alias') % self.name
parser = subparsers.add_parser(cmd_name, **opts)
break

Expand Down
2 changes: 1 addition & 1 deletion deluge/ui/console/cmdline/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def add_arguments(self, parser):
'--state',
action='store',
dest='state',
help=_('Show torrents with state STATE: %s.' % (', '.join(STATES))),
help=_('Show torrents with state STATE: %s.') % (', '.join(STATES)),
)
parser.add_argument(
'--sort',
Expand Down
11 changes: 6 additions & 5 deletions deluge/ui/gtk3/addtorrentdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ def show_already_added_dialog(self, count):
_('Duplicate torrent(s)'),
_(
'You cannot add the same torrent twice.'
' %d torrents were already added.' % count
),
' %d torrents were already added.'
)
% count,
self.dialog,
).run()

Expand Down Expand Up @@ -585,9 +586,9 @@ def build_priorities(self, _iter, priorities):
self.files_treestore.iter_children(_iter), priorities
)
elif not self.files_treestore.get_value(_iter, 1).endswith('/'):
priorities[
self.files_treestore.get_value(_iter, 3)
] = self.files_treestore.get_value(_iter, 0)
priorities[self.files_treestore.get_value(_iter, 3)] = (
self.files_treestore.get_value(_iter, 0)
)
_iter = self.files_treestore.iter_next(_iter)
return priorities

Expand Down
3 changes: 1 addition & 2 deletions deluge/ui/gtk3/gtkui.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ def _on_reactor_start(self):
err_msg = _(
'Only Thin Client mode is available due to libtorrent import error: %s\n'
'To use Standalone mode, please see logs for error details.'
% (str(ex))
)
) % (str(ex))

except ImportError as ex:
log.exception(ex)
Expand Down
40 changes: 21 additions & 19 deletions deluge/ui/gtk3/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,20 @@ def load_languages(self):
self.language_checkbox = self.builder.get_object('checkbutton_language')
lang_model = self.language_combo.get_model()
langs = get_languages()
index = -1
for i, l in enumerate(langs):
lang_code, name = l
lang_idx = -1
for idx, lang in enumerate(langs):
lang_code, name = lang
lang_model.append([lang_code, name])
if self.gtkui_config['language'] == lang_code:
index = i
lang_idx = idx

if self.gtkui_config['language'] is None:
self.language_checkbox.set_active(True)
self.language_combo.set_visible(False)
else:
self.language_combo.set_visible(True)
if index != -1:
self.language_combo.set_active(index)
if lang_idx != -1:
self.language_combo.set_active(lang_idx)

def __del__(self):
del self.gtkui_config
Expand Down Expand Up @@ -647,15 +647,15 @@ def set_config(self, hide=False):
'chk_move_completed'
).get_active()

new_core_config[
'download_location'
] = self.download_location_path_chooser.get_text()
new_core_config[
'move_completed_path'
] = self.move_completed_path_chooser.get_text()
new_core_config[
'torrentfiles_location'
] = self.copy_torrent_files_path_chooser.get_text()
new_core_config['download_location'] = (
self.download_location_path_chooser.get_text()
)
new_core_config['move_completed_path'] = (
self.move_completed_path_chooser.get_text()
)
new_core_config['torrentfiles_location'] = (
self.copy_torrent_files_path_chooser.get_text()
)
new_core_config['prioritize_first_last_pieces'] = self.builder.get_object(
'chk_prioritize_first_last_pieces'
).get_active()
Expand Down Expand Up @@ -956,7 +956,7 @@ def on_response(response):
mode = _('Thinclient') if was_standalone else _('Standalone')
dialog = YesNoDialog(
_('Switching Deluge Client Mode...'),
_('Do you want to restart to use %s mode?' % mode),
_('Do you want to restart to use %s mode?') % mode,
)
dialog.run().addCallback(on_response)

Expand Down Expand Up @@ -1381,7 +1381,9 @@ async def on_accounts_add_clicked(self, widget):
except Exception as ex:
return ErrorDialog(
_('Error Adding Account'),
_(f'An error occurred while adding account: {account}'),
_('An error occurred while adding account: {account}').format(

This comment has been minimized.

Copy link
@kuraga

kuraga Sep 9, 2024

@cas-- , : {account} should be outside of _(...) or be : %s?

This comment has been minimized.

Copy link
@cas--

cas-- Sep 9, 2024

Author Member

Hmm it should work with late format since gettext func will return string with account substitution in place, are you seeing an issue with it?

This comment has been minimized.

Copy link
@kuraga

kuraga Sep 9, 2024

Yes, my fault.

This comment has been minimized.

Copy link
@kuraga

kuraga Sep 9, 2024

@cas-- , taking this opportunity, take a look at https://dev.deluge-torrent.org/ticket/3542, please. Thanks :)

account=account
),
parent=self.pref_dialog,
details=ex,
).run()
Expand Down Expand Up @@ -1434,8 +1436,8 @@ def on_accounts_delete_clicked(self, widget):
header = _('Remove Account')
text = _(
'Are you sure you want to remove the account with the '
'username "%(username)s"?' % {'username': username}
)
'username "%(username)s"?'
) % {'username': username}
dialog = YesNoDialog(header, text, parent=self.pref_dialog)

def dialog_finished(response_id):
Expand Down

0 comments on commit 2247668

Please sign in to comment.