Enable the bad-exit-annotation ruff rule and fix related warnings (#3564)

This commit is contained in:
correctmost 2025-06-01 09:41:34 +00:00 committed by GitHub
parent 55fd59d94e
commit a580da2bbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 27 additions and 20 deletions

View File

@ -1,5 +1,6 @@
import time
from collections.abc import Iterator
from types import TracebackType
from .exceptions import SysCallError
from .general import SysCommand, SysCommandWorker, locate_binary
@ -47,13 +48,13 @@ class Boot:
storage['active_boot'] = self
return self
def __exit__(self, *args: str, **kwargs: str) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
if len(args) >= 2 and args[1]:
if exc_type is not None:
error(
args[1],
str(exc_value),
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
)

View File

@ -16,6 +16,7 @@ from enum import Enum
from pathlib import Path
from select import EPOLLHUP, EPOLLIN, epoll
from shutil import which
from types import TracebackType
from typing import Any, override
from .exceptions import RequirementError, SysCallError
@ -170,7 +171,7 @@ class SysCommandWorker:
def __enter__(self) -> 'SysCommandWorker':
return self
def __exit__(self, *args: str) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
@ -186,8 +187,8 @@ class SysCommandWorker:
sys.stdout.write('\n')
sys.stdout.flush()
if len(args) >= 2 and args[1]:
debug(args[1])
if exc_type is not None:
debug(str(exc_value))
if self.exit_code != 0:
raise SysCallError(
@ -327,12 +328,12 @@ class SysCommand:
def __enter__(self) -> SysCommandWorker | None:
return self.session
def __exit__(self, *args: str, **kwargs: dict[str, Any]) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
if len(args) >= 2 and args[1]:
error(args[1])
if exc_type is not None:
error(str(exc_value))
def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes]:
if self.session:

View File

@ -124,9 +124,9 @@ class Installer:
def __enter__(self) -> 'Installer':
return self
def __exit__(self, exc_type: type[BaseException] | None, exc_val, exc_tb: TracebackType | None) -> bool:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> bool | None:
if exc_type is not None:
error(exc_val)
error(str(exc_value))
self.sync_log_to_install_medium()
@ -134,7 +134,9 @@ class Installer:
# and then reboot, and a identical log file will be found in the ISO medium anyway.
Tui.print(str(tr('[!] A log file has been created here: {}').format(logger.path)))
Tui.print(tr('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues'))
raise exc_val
# Return None to propagate the exception
return None
if not (missing_steps := self.post_install_check()):
msg = f'Installation completed without any errors.\nLog files temporarily available at {logger.directory}.\nYou may reboot when ready.\n'

View File

@ -4,6 +4,7 @@ import shlex
from dataclasses import dataclass
from pathlib import Path
from subprocess import CalledProcessError
from types import TracebackType
from archinstall.lib.disk.utils import get_lsblk_info, umount
@ -47,7 +48,7 @@ class Luks2:
def __enter__(self) -> None:
self.unlock(self.key_file)
def __exit__(self, *args: str, **kwargs: str) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
if self.auto_unmount:
self.lock()

View File

@ -1,5 +1,6 @@
from __future__ import annotations
from types import TracebackType
from typing import Any, Self
from archinstall.lib.translationhandler import tr
@ -36,13 +37,15 @@ class AbstractMenu[ValueT]:
self.is_context_mgr = True
return self
def __exit__(self, *args: Any, **kwargs: Any) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
# TODO: skip processing when it comes from a planified exit
if len(args) >= 2 and args[1]:
error(args[1])
if exc_type is not None:
error(str(exc_value))
Tui.print('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues')
raise args[1]
# Return None to propagate the exception
return None
self.sync_all_to_config()

View File

@ -49,7 +49,7 @@ class DownloadTimer:
self.start_time = time.time()
return self
def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
if self.start_time:
time_delta = time.time() - self.start_time
signal.alarm(0)

View File

@ -1225,7 +1225,7 @@ class Tui:
tui = self.init()
Tui._t = tui
def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, tb: TracebackType | None) -> None:
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
self.stop()
@property

View File

@ -225,7 +225,6 @@ ignore = [
"PLW1514", # unspecified-encoding
"PLW1641", # eq-without-hash
"PLW2901", # redefined-loop-name
"PYI036", # bad-exit-annotation
"RUF005", # collection-literal-concatenation
"RUF015", # unnecessary-iterable-allocation-for-first-element
"RUF039", # unraw-re-pattern