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

Expand mypy checks to include more files and more checks #2651

Merged
merged 1 commit into from
Aug 28, 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: 1 addition & 3 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ jobs:
- run: python --version
- run: mypy --version
- name: run mypy
run: mypy --config-file pyproject.toml
- name: run mypy strict
run: mypy --config-file mypy.ini
run: mypy
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
args: [--config=pyproject.toml]
fail_fast: true
2 changes: 1 addition & 1 deletion archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
from typing import List, Dict, Any, Optional, TYPE_CHECKING, Literal, Iterable

from parted import ( # type: ignore
from parted import (
Disk, Geometry, FileSystem,
PartitionException, DiskException,
getDevice, getAllDevices, newDisk, freshDisk, Partition, Device
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/disk/device_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Optional, List, Dict, TYPE_CHECKING, Any
from typing import Union

import parted # type: ignore
import parted
import _ped # type: ignore
from parted import Disk, Geometry, Partition

Expand Down Expand Up @@ -623,7 +623,7 @@ def fs_type_mount(self) -> str:
match self:
case FilesystemType.Ntfs: return 'ntfs3'
case FilesystemType.Fat32: return 'vfat'
case _: return self.value # type: ignore
case _: return self.value

@property
def installation_pkg(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def copy_iso_network_config(self, enable_services: bool = False) -> bool:
# This function will be called after minimal_installation()
# as a hook for post-installs. This hook is only needed if
# base is not installed yet.
def post_install_enable_iwd_service(*args: str, **kwargs: str):
def post_install_enable_iwd_service(*args: str, **kwargs: str) -> None:
self.enable_service('iwd')

self.post_base_install.append(post_install_enable_iwd_service)
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/interactions/general_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def ask_additional_packages_to_install(preset: List[str] = []) -> List[str]:
print(_('Only packages such as base, base-devel, linux, linux-firmware, efibootmgr and optional profile packages are installed.'))
print(_('If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.'))

def read_packages(p: List = []) -> list:
def read_packages(p: list[str] = []) -> list[str]:
display = ' '.join(p)
input_packages = TextInput(_('Write additional packages to install (space separated, leave blank to skip): '), display).run().strip()
return input_packages.split() if input_packages else []
Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/menu/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os import system
from typing import Dict, List, Union, Any, TYPE_CHECKING, Optional, Callable

from simple_term_menu import TerminalMenu # type: ignore
from simple_term_menu import TerminalMenu

from ..exceptions import RequirementError
from ..output import debug
Expand Down Expand Up @@ -33,7 +33,7 @@ def multi_value(self) -> List[Any]:
return self.value # type: ignore


class Menu(TerminalMenu):
class Menu(TerminalMenu): # type: ignore[misc]
_menu_is_active: bool = False

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def calc_checksum(icmp_packet) -> int:

return checksum

def build_icmp(payload):
def build_icmp(payload: bytes) -> bytes:
# Define the ICMP Echo Request packet
icmp_packet = struct.pack('!BBHHH', 8, 0, 0, 0, 1) + payload

Expand Down
2 changes: 1 addition & 1 deletion archinstall/tui/menu_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __post_init__(self) -> None:
raise ValueError('Selected item not in menu')

@staticmethod
def default_confirm():
def default_confirm() -> 'MenuItemGroup':
return MenuItemGroup(
[MenuItem.default_yes(), MenuItem.default_no()],
sort_items=False
Expand Down
4 changes: 2 additions & 2 deletions examples/interactive_installation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Callable, Optional

import archinstall
from archinstall import Installer
Expand All @@ -12,7 +12,7 @@
from archinstall import info, debug

if TYPE_CHECKING:
_: Any
_: Callable[[str], str]


def ask_user_questions() -> None:
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal_installation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, List
from typing import TYPE_CHECKING, Callable, List

import archinstall
from archinstall import disk
Expand All @@ -10,7 +10,7 @@
from archinstall.default_profiles.minimal import MinimalProfile

if TYPE_CHECKING:
_: Any
_: Callable[[str], str]


def perform_installation(mountpoint: Path) -> None:
Expand Down
20 changes: 0 additions & 20 deletions mypy.ini

This file was deleted.

55 changes: 52 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,58 @@ archinstall = "archinstall"

[tool.mypy]
python_version = "3.11"
files = "archinstall/"
exclude = "tests"
check_untyped_defs=true
files = "."
exclude = "^build/"
check_untyped_defs = true
disallow_any_explicit = false
disallow_any_expr = false
disallow_any_generics = false
disallow_any_unimported = false
disallow_incomplete_defs = false
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = false
extra_checks = true
strict = false
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "archinstall.examples.*"
disallow_any_explicit = true
disallow_any_generics = true
disallow_any_unimported = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
follow_imports = "silent"

[[tool.mypy.overrides]]
module = "archinstall.lib.*"
strict_equality = false
warn_return_any = false
warn_unreachable = false

[[tool.mypy.overrides]]
module = "archinstall.scripts.*"
warn_unreachable = false

[[tool.mypy.overrides]]
module = "archinstall.tui.*"
strict_equality = false
warn_return_any = false
warn_unreachable = false

[[tool.mypy.overrides]]
module = [
"parted",
"simple_term_menu",
]
ignore_missing_imports = true

[tool.bandit]
targets = ["archinstall"]
Expand Down