Skip to content

Commit b8967d3

Browse files
committed
Enable the bad-exit-annotation ruff rule and fix related warnings
1 parent 55fd59d commit b8967d3

File tree

8 files changed

+27
-20
lines changed

8 files changed

+27
-20
lines changed

archinstall/lib/boot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
from collections.abc import Iterator
3+
from types import TracebackType
34

45
from .exceptions import SysCallError
56
from .general import SysCommand, SysCommandWorker, locate_binary
@@ -47,13 +48,13 @@ def __enter__(self) -> 'Boot':
4748
storage['active_boot'] = self
4849
return self
4950

50-
def __exit__(self, *args: str, **kwargs: str) -> None:
51+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
5152
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
5253
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
5354

54-
if len(args) >= 2 and args[1]:
55+
if exc_type is not None:
5556
error(
56-
args[1],
57+
str(exc_value),
5758
f'The error above occurred in a temporary boot-up of the installation {self.instance}',
5859
)
5960

archinstall/lib/general.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pathlib import Path
1717
from select import EPOLLHUP, EPOLLIN, epoll
1818
from shutil import which
19+
from types import TracebackType
1920
from typing import Any, override
2021

2122
from .exceptions import RequirementError, SysCallError
@@ -170,7 +171,7 @@ def __str__(self) -> str:
170171
def __enter__(self) -> 'SysCommandWorker':
171172
return self
172173

173-
def __exit__(self, *args: str) -> None:
174+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
174175
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
175176
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
176177

@@ -186,8 +187,8 @@ def __exit__(self, *args: str) -> None:
186187
sys.stdout.write('\n')
187188
sys.stdout.flush()
188189

189-
if len(args) >= 2 and args[1]:
190-
debug(args[1])
190+
if exc_type is not None:
191+
debug(str(exc_value))
191192

192193
if self.exit_code != 0:
193194
raise SysCallError(
@@ -327,12 +328,12 @@ def __init__(
327328
def __enter__(self) -> SysCommandWorker | None:
328329
return self.session
329330

330-
def __exit__(self, *args: str, **kwargs: dict[str, Any]) -> None:
331+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
331332
# b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync.
332333
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
333334

334-
if len(args) >= 2 and args[1]:
335-
error(args[1])
335+
if exc_type is not None:
336+
error(str(exc_value))
336337

337338
def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes]:
338339
if self.session:

archinstall/lib/installer.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,19 @@ def __init__(
124124
def __enter__(self) -> 'Installer':
125125
return self
126126

127-
def __exit__(self, exc_type: type[BaseException] | None, exc_val, exc_tb: TracebackType | None) -> bool:
127+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> bool | None:
128128
if exc_type is not None:
129-
error(exc_val)
129+
error(str(exc_value))
130130

131131
self.sync_log_to_install_medium()
132132

133133
# We avoid printing /mnt/<log path> because that might confuse people if they note it down
134134
# and then reboot, and a identical log file will be found in the ISO medium anyway.
135135
Tui.print(str(tr('[!] A log file has been created here: {}').format(logger.path)))
136136
Tui.print(tr('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues'))
137-
raise exc_val
137+
138+
# Return None to propagate the exception
139+
return None
138140

139141
if not (missing_steps := self.post_install_check()):
140142
msg = f'Installation completed without any errors.\nLog files temporarily available at {logger.directory}.\nYou may reboot when ready.\n'

archinstall/lib/luks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from dataclasses import dataclass
55
from pathlib import Path
66
from subprocess import CalledProcessError
7+
from types import TracebackType
78

89
from archinstall.lib.disk.utils import get_lsblk_info, umount
910

@@ -47,7 +48,7 @@ def __post_init__(self) -> None:
4748
def __enter__(self) -> None:
4849
self.unlock(self.key_file)
4950

50-
def __exit__(self, *args: str, **kwargs: str) -> None:
51+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
5152
if self.auto_unmount:
5253
self.lock()
5354

archinstall/lib/menu/abstract_menu.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from types import TracebackType
34
from typing import Any, Self
45

56
from archinstall.lib.translationhandler import tr
@@ -36,13 +37,15 @@ def __enter__(self, *args: Any, **kwargs: Any) -> Self:
3637
self.is_context_mgr = True
3738
return self
3839

39-
def __exit__(self, *args: Any, **kwargs: Any) -> None:
40+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
4041
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
4142
# TODO: skip processing when it comes from a planified exit
42-
if len(args) >= 2 and args[1]:
43-
error(args[1])
43+
if exc_type is not None:
44+
error(str(exc_value))
4445
Tui.print('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues')
45-
raise args[1]
46+
47+
# Return None to propagate the exception
48+
return None
4649

4750
self.sync_all_to_config()
4851

archinstall/lib/networking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __enter__(self) -> Self:
4949
self.start_time = time.time()
5050
return self
5151

52-
def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None:
52+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
5353
if self.start_time:
5454
time_delta = time.time() - self.start_time
5555
signal.alarm(0)

archinstall/tui/curses_menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def __enter__(self) -> None:
12251225
tui = self.init()
12261226
Tui._t = tui
12271227

1228-
def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, tb: TracebackType | None) -> None:
1228+
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
12291229
self.stop()
12301230

12311231
@property

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ ignore = [
225225
"PLW1514", # unspecified-encoding
226226
"PLW1641", # eq-without-hash
227227
"PLW2901", # redefined-loop-name
228-
"PYI036", # bad-exit-annotation
229228
"RUF005", # collection-literal-concatenation
230229
"RUF015", # unnecessary-iterable-allocation-for-first-element
231230
"RUF039", # unraw-re-pattern

0 commit comments

Comments
 (0)