diff options
author | Calum Lind <calumlind+deluge@gmail.com> | 2024-09-08 14:24:44 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2024-09-08 18:48:43 +0200 |
commit | 22476685713e8f2387ecf40570f563597fe56bfb (patch) | |
tree | 8852c36b46fd0cded9d47939b7b7cfa746c9129f | |
parent | [Typing] Add pyright config to suppress warnings (diff) | |
download | deluge-22476685713e8f2387ecf40570f563597fe56bfb.tar.xz deluge-22476685713e8f2387ecf40570f563597fe56bfb.zip |
[Lint] Fix ruff lint gettext and type comparison
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/
-rw-r--r-- | deluge/plugins/Blocklist/deluge_blocklist/common.py | 6 | ||||
-rw-r--r-- | deluge/tests/test_json_api.py | 2 | ||||
-rw-r--r-- | deluge/tests/test_log.py | 2 | ||||
-rw-r--r-- | deluge/tests/test_ui_entry.py | 2 | ||||
-rw-r--r-- | deluge/tests/test_web_api.py | 2 | ||||
-rw-r--r-- | deluge/ui/console/cmdline/command.py | 2 | ||||
-rw-r--r-- | deluge/ui/console/cmdline/commands/info.py | 2 | ||||
-rw-r--r-- | deluge/ui/gtk3/addtorrentdialog.py | 11 | ||||
-rw-r--r-- | deluge/ui/gtk3/gtkui.py | 3 | ||||
-rw-r--r-- | deluge/ui/gtk3/preferences.py | 40 |
10 files changed, 37 insertions, 35 deletions
diff --git a/deluge/plugins/Blocklist/deluge_blocklist/common.py b/deluge/plugins/Blocklist/deluge_blocklist/common.py index 35b2f87c5..f1059413d 100644 --- a/deluge/plugins/Blocklist/deluge_blocklist/common.py +++ b/deluge/plugins/Blocklist/deluge_blocklist/common.py @@ -107,11 +107,11 @@ class 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): diff --git a/deluge/tests/test_json_api.py b/deluge/tests/test_json_api.py index ef21e9410..d8e382f38 100644 --- a/deluge/tests/test_json_api.py +++ b/deluge/tests/test_json_api.py @@ -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): diff --git a/deluge/tests/test_log.py b/deluge/tests/test_log.py index f0dcbee86..24bd27f9c 100644 --- a/deluge/tests/test_log.py +++ b/deluge/tests/test_log.py @@ -28,7 +28,7 @@ class TestLog(BaseTestCase): # 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 diff --git a/deluge/tests/test_ui_entry.py b/deluge/tests/test_ui_entry.py index 9a1330ed5..b0948f467 100644 --- a/deluge/tests/test_ui_entry.py +++ b/deluge/tests/test_ui_entry.py @@ -330,7 +330,7 @@ class ConsoleUIWithDaemonBaseTestCase(UIWithDaemonBaseTestCase): 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( diff --git a/deluge/tests/test_web_api.py b/deluge/tests/test_web_api.py index 4dfa58d7c..eac716377 100644 --- a/deluge/tests/test_web_api.py +++ b/deluge/tests/test_web_api.py @@ -34,7 +34,7 @@ class TestWebAPI(WebServerTestBase): 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 diff --git a/deluge/ui/console/cmdline/command.py b/deluge/ui/console/cmdline/command.py index 63dc9265a..1de035722 100644 --- a/deluge/ui/console/cmdline/command.py +++ b/deluge/ui/console/cmdline/command.py @@ -201,7 +201,7 @@ class BaseCommand: 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 diff --git a/deluge/ui/console/cmdline/commands/info.py b/deluge/ui/console/cmdline/commands/info.py index 7ea9a6773..09b2458ee 100644 --- a/deluge/ui/console/cmdline/commands/info.py +++ b/deluge/ui/console/cmdline/commands/info.py @@ -111,7 +111,7 @@ class Command(BaseCommand): '--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', diff --git a/deluge/ui/gtk3/addtorrentdialog.py b/deluge/ui/gtk3/addtorrentdialog.py index aa71cc434..7e752bc99 100644 --- a/deluge/ui/gtk3/addtorrentdialog.py +++ b/deluge/ui/gtk3/addtorrentdialog.py @@ -236,8 +236,9 @@ class AddTorrentDialog(component.Component): _('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() @@ -585,9 +586,9 @@ class AddTorrentDialog(component.Component): 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 diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 73a7c97ae..a0c5d8942 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -324,8 +324,7 @@ class GtkUI: 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) diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index cd67a5b09..59b22264b 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -226,20 +226,20 @@ class Preferences(component.Component): 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 @@ -647,15 +647,15 @@ class Preferences(component.Component): '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() @@ -956,7 +956,7 @@ class Preferences(component.Component): 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) @@ -1381,7 +1381,9 @@ class Preferences(component.Component): 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( + account=account + ), parent=self.pref_dialog, details=ex, ).run() @@ -1434,8 +1436,8 @@ class Preferences(component.Component): 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): |