Replace __enter__ return type with Self (#4121)

This commit is contained in:
codefiles 2026-01-13 09:45:21 -05:00 committed by GitHub
parent b779345a5b
commit 8f7d59b718
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import time import time
from collections.abc import Iterator from collections.abc import Iterator
from types import TracebackType from types import TracebackType
from typing import Self
from .exceptions import SysCallError from .exceptions import SysCallError
from .general import SysCommand, SysCommandWorker, locate_binary from .general import SysCommand, SysCommandWorker, locate_binary
@ -16,7 +17,7 @@ class Boot:
self.session: SysCommandWorker | None = None self.session: SysCommandWorker | None = None
self.ready = False self.ready = False
def __enter__(self) -> 'Boot': def __enter__(self) -> Self:
if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance: if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance:
raise KeyError('Archinstall only supports booting up one instance and another session is already active.') raise KeyError('Archinstall only supports booting up one instance and another session is already active.')

View File

@ -15,7 +15,7 @@ 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 types import TracebackType
from typing import Any, override from typing import Any, Self, override
from .exceptions import RequirementError, SysCallError from .exceptions import RequirementError, SysCallError
from .output import debug, error, logger from .output import debug, error, logger
@ -177,7 +177,7 @@ class SysCommandWorker:
except UnicodeDecodeError: except UnicodeDecodeError:
return str(self._trace_log) return str(self._trace_log)
def __enter__(self) -> 'SysCommandWorker': def __enter__(self) -> Self:
return self return self
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None: def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:

View File

@ -11,7 +11,7 @@ from collections.abc import Callable
from pathlib import Path from pathlib import Path
from subprocess import CalledProcessError from subprocess import CalledProcessError
from types import TracebackType from types import TracebackType
from typing import Any from typing import Any, Self
from archinstall.lib.disk.device_handler import device_handler from archinstall.lib.disk.device_handler import device_handler
from archinstall.lib.disk.fido import Fido2 from archinstall.lib.disk.fido import Fido2
@ -123,7 +123,7 @@ class Installer:
self.pacman = Pacman(self.target, arch_config_handler.args.silent) self.pacman = Pacman(self.target, arch_config_handler.args.silent)
def __enter__(self) -> 'Installer': def __enter__(self) -> Self:
return self return self
def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> bool | None: def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> bool | None: