Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various mypy errors in archinstall/lib/ #2640

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions archinstall/lib/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def is_alive(self) -> bool:

return self.session.is_alive()

def SysCommand(self, cmd: list, *args, **kwargs) -> SysCommand:
def SysCommand(self, cmd: list[str], *args, **kwargs) -> SysCommand:
if cmd[0][0] != '/' and cmd[0][:2] != './':
# This check is also done in SysCommand & SysCommandWorker.
# However, that check is done for `machinectl` and not for our chroot command.
Expand All @@ -104,7 +104,7 @@ def SysCommand(self, cmd: list, *args, **kwargs) -> SysCommand:

return SysCommand(["systemd-run", f"--machine={self.container_name}", "--pty", *cmd], *args, **kwargs)

def SysCommandWorker(self, cmd: list, *args, **kwargs) -> SysCommandWorker:
def SysCommandWorker(self, cmd: list[str], *args, **kwargs) -> SysCommandWorker:
if cmd[0][0] != '/' and cmd[0][:2] != './':
cmd[0] = locate_binary(cmd[0])

Expand Down
18 changes: 9 additions & 9 deletions archinstall/lib/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def __init__(self, config: Dict):
self._process_config()

@property
def user_credentials_file(self):
def user_credentials_file(self) -> str:
return self._user_creds_file

@property
def user_configuration_file(self):
def user_configuration_file(self) -> str:
return self._user_config_file

def _process_config(self):
def _process_config(self) -> None:
for key, value in self._config.items():
if key in self._sensitive:
self._user_credentials[key] = value
Expand All @@ -68,7 +68,7 @@ def user_credentials_to_json(self) -> Optional[str]:
return json.dumps(self._user_credentials, indent=4, sort_keys=True, cls=UNSAFE_JSON)
return None

def show(self):
def show(self) -> None:
print(_('\nThis is your chosen configuration:'))
debug(" -- Chosen configuration --")

Expand All @@ -84,29 +84,29 @@ def _is_valid_path(self, dest_path: Path) -> bool:
)
return dest_path_ok

def save_user_config(self, dest_path: Path):
def save_user_config(self, dest_path: Path) -> None:
if self._is_valid_path(dest_path):
target = dest_path / self._user_config_file
target.write_text(self.user_config_to_json())
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)

def save_user_creds(self, dest_path: Path):
def save_user_creds(self, dest_path: Path) -> None:
if self._is_valid_path(dest_path):
if user_creds := self.user_credentials_to_json():
target = dest_path / self._user_creds_file
target.write_text(user_creds)
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)

def save(self, dest_path: Optional[Path] = None):
def save(self, dest_path: Optional[Path] = None) -> None:
dest_path = dest_path or self._default_save_path

if self._is_valid_path(dest_path):
self.save_user_config(dest_path)
self.save_user_creds(dest_path)


def save_config(config: Dict):
def preview(selection: str):
def save_config(config: Dict) -> None:
def preview(selection: str) -> Optional[str]:
match options[selection]:
case "user_config":
serialized = config_output.user_config_to_json()
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def create_session(self) -> bool:

return True

def decode(self, encoding: str = 'utf-8', errors='backslashreplace', strip: bool = True) -> str:
def decode(self, encoding: str = 'utf-8', errors: str = 'backslashreplace', strip: bool = True) -> str:
if not self.session:
raise ValueError('No session available to decode')

Expand Down Expand Up @@ -520,6 +520,6 @@ def json_stream_to_structure(configuration_identifier : str, stream :str, target
return True


def secret(x :str):
def secret(x :str) -> str:
""" return * with len equal to to the input string """
return '*' * len(x)
14 changes: 7 additions & 7 deletions archinstall/lib/global_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class GlobalMenu(AbstractMenu):
def __init__(self, data_store: Dict[str, Any]):
super().__init__(data_store=data_store, auto_cursor=True, preview_size=0.3)

def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
# archinstall.Language will not use preset values
self._menu_options['archinstall-language'] = \
Selector(
Expand Down Expand Up @@ -181,7 +181,7 @@ def setup_selection_menu_options(self):
self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1))

def _missing_configs(self) -> List[str]:
def check(s) -> bool:
def check(s: str) -> bool:
obj = self._menu_options.get(s)
if obj and obj.has_selection():
return True
Expand Down Expand Up @@ -216,23 +216,23 @@ def _is_config_valid(self) -> bool:
return False
return self._validate_bootloader() is None

def _update_uki_display(self, name: Optional[str] = None):
def _update_uki_display(self, name: Optional[str] = None) -> None:
if bootloader := self._menu_options['bootloader'].current_selection:
if not SysInfo.has_uefi() or not bootloader.has_uki_support():
self._menu_options['uki'].set_current_selection(False)
self._menu_options['uki'].set_enabled(False)
elif name and name == 'bootloader':
self._menu_options['uki'].set_enabled(True)

def _update_install_text(self, name: Optional[str] = None, value: Any = None):
def _update_install_text(self, name: Optional[str] = None, value: Any = None) -> None:
text = self._install_text()
self._menu_options['install'].update_description(text)

def post_callback(self, name: Optional[str] = None, value: Any = None):
def post_callback(self, name: Optional[str] = None, value: Any = None) -> None:
self._update_uki_display(name)
self._update_install_text(name, value)

def _install_text(self):
def _install_text(self) -> str:
missing = len(self._missing_configs())
if missing > 0:
return _('Install ({} config(s) missing)').format(missing)
Expand Down Expand Up @@ -281,7 +281,7 @@ def _prev_network_config(self) -> Optional[str]:
return output
return None

def _prev_additional_pkgs(self):
def _prev_additional_pkgs(self) -> Optional[str]:
selector = self._menu_options['packages']
if selector.current_selection:
packages: List[str] = selector.current_selection
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def gfx_packages(self) -> List[GfxPackage]:
return packages

class _SysInfo:
def __init__(self):
def __init__(self) -> None:
pass

@cached_property
Expand Down
Loading