static-code: apply ruff fixes

fix ruff ignore exceptions
This commit is contained in:
tomasmatus 2026-08-18 16:08:54 +02:00 committed by Freya Gustavsson
parent c1bcf86373
commit bd2c0ef9c4
12 changed files with 26 additions and 26 deletions

View file

@ -18,13 +18,13 @@ import textwrap
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import GLib, Gio, Gtk # noqa: I001, E402
from gi.repository import GLib, Gio, Gtk # ruff: ignore[unsorted-imports, module-import-not-at-top-of-file]
gi.require_version("WebKit", "6.0")
from gi.repository import WebKit # noqa: E402
from gi.repository import WebKit # ruff: ignore[module-import-not-at-top-of-file]
gi.require_version("Adw", "1")
from gi.repository import Adw # noqa: E402
from gi.repository import Adw # ruff: ignore[module-import-not-at-top-of-file]
libexecdir = os.path.realpath(__file__ + '/..')

View file

@ -14,7 +14,7 @@ from .session import SessionControlChannel
from .stream import SocketStreamChannel, SubprocessStreamChannel
from .trivial import EchoChannel, NullChannel
CHANNEL_TYPES = [ # noqa: RUF067
CHANNEL_TYPES = [ # ruff: ignore[non-empty-init-module]
DBusChannel,
EchoChannel,
FsInfoChannel,

View file

@ -338,7 +338,7 @@ class DBusChannel(Channel):
self.send_json(
reply=[reply.get_body()], id=cookie,
flags="<" if flags is not None else None,
type=reply.get_signature(True)) # noqa: FBT003
type=reply.get_signature(True)) # ruff: ignore[boolean-positional-value-in-call]
except BusError as error:
# actually, should send the fields from the message body
self.send_json(error=[error.name, [error.message]], id=cookie)

View file

@ -142,7 +142,7 @@ class FsReadChannel(GeneratorChannel):
except FileNotFoundError:
# Using `yield` and `return {value}` generator, but GeneratorChannel does expect this
return {'tag': '-'} # noqa: B901
return {'tag': '-'} # ruff: ignore[return-in-generator]
except PermissionError as exc:
raise ChannelError('access-denied') from exc
except OSError as exc:
@ -638,7 +638,7 @@ class FsInfoChannel(Channel, PathWatchListener):
try:
fd = Handle.open(self.path, os.O_PATH if self.follow else os.O_PATH | os.O_NOFOLLOW)
except OSError as exc:
assert exc.errno # noqa: PT017 - mypy thinks that errno can be None
assert exc.errno # ruff: ignore[pytest-assert-in-except] - mypy thinks that errno can be None
self.report_error(exc.errno)
else:
self.report_initial_state(fd)

View file

@ -1,7 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
import sys
if sys.version_info >= (3, 11): # noqa: RUF067
if sys.version_info >= (3, 11): # ruff: ignore[non-empty-init-module]
import importlib.resources
def read_cockpit_data_file(filename: str) -> bytes:

View file

@ -8,7 +8,7 @@ import ast
import json
import os
import pydoc
import readline # noqa: F401, side-effecting import
import readline # ruff: ignore[unused-import], side-effecting import
import shlex
import sys
import time

View file

@ -2833,9 +2833,9 @@ def arg_parser(enable_sit: bool = True) -> argparse.ArgumentParser:
def test_main(
options: argparse.Namespace | None = None, # noqa: PT028
suite: unittest.TestSuite | None = None, # noqa: PT028
attachments: str | None = None, # noqa: PT028
options: argparse.Namespace | None = None, # ruff: ignore[pytest-parameter-with-default-argument]
suite: unittest.TestSuite | None = None, # ruff: ignore[pytest-parameter-with-default-argument]
attachments: str | None = None, # ruff: ignore[pytest-parameter-with-default-argument]
) -> int:
"""
Run all test cases, as indicated by arguments.

View file

@ -18,17 +18,17 @@ class TestExample(testlib.MachineCase):
@unittest.expectedFailure
def testExpectedFail(self):
self.login_and_go("/system")
self.assertFalse(True) # noqa: FBT003
self.assertFalse(True) # ruff: ignore[boolean-positional-value-in-call]
def testFail(self):
self.login_and_go("/system")
if os.environ.get('TEST_FAILURES'):
self.assertFalse(True) # noqa: FBT003
self.assertFalse(True) # ruff: ignore[boolean-positional-value-in-call]
@unittest.skip('not supported')
def testSkip(self):
self.login_and_go("/system")
self.assertFalse(True) # noqa: FBT003
self.assertFalse(True) # ruff: ignore[boolean-positional-value-in-call]
def testRaiseSkip(self):
raise unittest.SkipTest("dynamic skip")
@ -60,14 +60,14 @@ class TestSimple(unittest.TestCase):
sys.stderr.write(">1%i\n" % i)
else:
print(">2", i)
self.assertTrue(True) # noqa: FBT003
self.assertTrue(True) # ruff: ignore[boolean-positional-value-in-call]
@unittest.expectedFailure
def testTwo(self):
self.assertFalse(True) # noqa: FBT003
self.assertFalse(True) # ruff: ignore[boolean-positional-value-in-call]
def testThree(self):
self.assertTrue(True) # noqa: FBT003
self.assertTrue(True) # ruff: ignore[boolean-positional-value-in-call]
class TestTodo(unittest.TestCase):

View file

@ -9,14 +9,14 @@ class NoTestRetryExample(unittest.TestCase):
def testFail(self):
if os.environ.get('TEST_FAILURES'):
self.assertFalse(True) # noqa: FBT003
self.assertFalse(True) # ruff: ignore[boolean-positional-value-in-call]
@testlib.no_retry_when_changed
def testNoRetry(self):
self.assertTrue(True) # noqa: FBT003
self.assertTrue(True) # ruff: ignore[boolean-positional-value-in-call]
def testBasic(self):
self.assertTrue(True) # noqa: FBT003
self.assertTrue(True) # ruff: ignore[boolean-positional-value-in-call]
if __name__ == '__main__':

View file

@ -41,7 +41,7 @@ def bridge():
# requires an event loop for queue in MockTransport
@pytest_asyncio.fixture
async def transport(bridge): # noqa: RUF029
async def transport(bridge): # ruff: ignore[unused-async]
return MockTransport(bridge)
@ -74,7 +74,7 @@ async def test_init_failure(rule, init_type, monkeypatch, transport):
# this doesn't use await, but requires an event loop
@pytest.mark.asyncio
async def test_immediate_shutdown(rule): # noqa: RUF029
async def test_immediate_shutdown(rule): # ruff: ignore[unused-async]
peer = rule.apply_rule({'payload': 'test'})
assert peer is not None
peer.close()

View file

@ -207,7 +207,7 @@ async def run_session_server(
logger.debug("run_session_server: starting on %r", socket_path)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.setblocking(False) # needed by .sock_accept() # noqa: FBT003
sock.setblocking(False) # needed by .sock_accept() # ruff: ignore[boolean-positional-value-in-call]
sock.bind(str(socket_path))
sock.listen()
logger.debug("run_session_server: listening")

View file

@ -26,8 +26,8 @@ import sys
BOTS_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "bots")
sys.path.insert(0, BOTS_DIR)
from lib.constants import DEFAULT_IDENTITY_FILE # noqa: E402
from machine.machine_core.ssh_connection import SSHConnection # noqa: E402
from lib.constants import DEFAULT_IDENTITY_FILE # ruff: ignore[module-import-not-at-top-of-file]
from machine.machine_core.ssh_connection import SSHConnection # ruff: ignore[module-import-not-at-top-of-file]
def find_cockpit_path(file_list: str) -> str: