Enable the bad-exit-annotation ruff rule and fix related warnings (#3564)
This commit is contained in:
parent
55fd59d94e
commit
a580da2bbd
|
|
@ -1,5 +1,6 @@
|
||||||
import time
|
import time
|
||||||
from collections.abc import Iterator
|
from collections.abc import Iterator
|
||||||
|
from types import TracebackType
|
||||||
|
|
||||||
from .exceptions import SysCallError
|
from .exceptions import SysCallError
|
||||||
from .general import SysCommand, SysCommandWorker, locate_binary
|
from .general import SysCommand, SysCommandWorker, locate_binary
|
||||||
|
|
@ -47,13 +48,13 @@ class Boot:
|
||||||
storage['active_boot'] = self
|
storage['active_boot'] = self
|
||||||
return 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.
|
# 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
|
# 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(
|
error(
|
||||||
args[1],
|
str(exc_value),
|
||||||
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
|
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from select import EPOLLHUP, EPOLLIN, epoll
|
from select import EPOLLHUP, EPOLLIN, epoll
|
||||||
from shutil import which
|
from shutil import which
|
||||||
|
from types import TracebackType
|
||||||
from typing import Any, override
|
from typing import Any, override
|
||||||
|
|
||||||
from .exceptions import RequirementError, SysCallError
|
from .exceptions import RequirementError, SysCallError
|
||||||
|
|
@ -170,7 +171,7 @@ class SysCommandWorker:
|
||||||
def __enter__(self) -> 'SysCommandWorker':
|
def __enter__(self) -> 'SysCommandWorker':
|
||||||
return self
|
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.
|
# 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
|
# 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.write('\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
if len(args) >= 2 and args[1]:
|
if exc_type is not None:
|
||||||
debug(args[1])
|
debug(str(exc_value))
|
||||||
|
|
||||||
if self.exit_code != 0:
|
if self.exit_code != 0:
|
||||||
raise SysCallError(
|
raise SysCallError(
|
||||||
|
|
@ -327,12 +328,12 @@ class SysCommand:
|
||||||
def __enter__(self) -> SysCommandWorker | None:
|
def __enter__(self) -> SysCommandWorker | None:
|
||||||
return self.session
|
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.
|
# 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
|
# 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])
|
error(str(exc_value))
|
||||||
|
|
||||||
def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes]:
|
def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes]:
|
||||||
if self.session:
|
if self.session:
|
||||||
|
|
|
||||||
|
|
@ -124,9 +124,9 @@ class Installer:
|
||||||
def __enter__(self) -> 'Installer':
|
def __enter__(self) -> 'Installer':
|
||||||
return self
|
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:
|
if exc_type is not None:
|
||||||
error(exc_val)
|
error(str(exc_value))
|
||||||
|
|
||||||
self.sync_log_to_install_medium()
|
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.
|
# 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(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'))
|
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()):
|
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'
|
msg = f'Installation completed without any errors.\nLog files temporarily available at {logger.directory}.\nYou may reboot when ready.\n'
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import shlex
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
|
from types import TracebackType
|
||||||
|
|
||||||
from archinstall.lib.disk.utils import get_lsblk_info, umount
|
from archinstall.lib.disk.utils import get_lsblk_info, umount
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ class Luks2:
|
||||||
def __enter__(self) -> None:
|
def __enter__(self) -> None:
|
||||||
self.unlock(self.key_file)
|
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:
|
if self.auto_unmount:
|
||||||
self.lock()
|
self.lock()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from types import TracebackType
|
||||||
from typing import Any, Self
|
from typing import Any, Self
|
||||||
|
|
||||||
from archinstall.lib.translationhandler import tr
|
from archinstall.lib.translationhandler import tr
|
||||||
|
|
@ -36,13 +37,15 @@ class AbstractMenu[ValueT]:
|
||||||
self.is_context_mgr = True
|
self.is_context_mgr = True
|
||||||
return self
|
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: 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
|
# TODO: skip processing when it comes from a planified exit
|
||||||
if len(args) >= 2 and args[1]:
|
if exc_type is not None:
|
||||||
error(args[1])
|
error(str(exc_value))
|
||||||
Tui.print('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues')
|
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()
|
self.sync_all_to_config()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class DownloadTimer:
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
return self
|
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:
|
if self.start_time:
|
||||||
time_delta = time.time() - self.start_time
|
time_delta = time.time() - self.start_time
|
||||||
signal.alarm(0)
|
signal.alarm(0)
|
||||||
|
|
|
||||||
|
|
@ -1225,7 +1225,7 @@ class Tui:
|
||||||
tui = self.init()
|
tui = self.init()
|
||||||
Tui._t = tui
|
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()
|
self.stop()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,6 @@ ignore = [
|
||||||
"PLW1514", # unspecified-encoding
|
"PLW1514", # unspecified-encoding
|
||||||
"PLW1641", # eq-without-hash
|
"PLW1641", # eq-without-hash
|
||||||
"PLW2901", # redefined-loop-name
|
"PLW2901", # redefined-loop-name
|
||||||
"PYI036", # bad-exit-annotation
|
|
||||||
"RUF005", # collection-literal-concatenation
|
"RUF005", # collection-literal-concatenation
|
||||||
"RUF015", # unnecessary-iterable-allocation-for-first-element
|
"RUF015", # unnecessary-iterable-allocation-for-first-element
|
||||||
"RUF039", # unraw-re-pattern
|
"RUF039", # unraw-re-pattern
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue