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

This commit also centralizes the mypy configuration in one spot.
This commit is contained in:
correctmost 2024-08-28 10:39:22 -04:00 committed by GitHub
parent 62d66e1caf
commit 7b5f1f72f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 66 additions and 40 deletions

View File

@ -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

View File

@ -38,5 +38,4 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
args: [--config=pyproject.toml]
fail_fast: true

View File

@ -8,7 +8,7 @@ import uuid
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

View File

@ -11,7 +11,7 @@ from pathlib import Path
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
@ -623,7 +623,7 @@ class FilesystemType(Enum):
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]:

View File

@ -665,7 +665,7 @@ class Installer:
# 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)

View File

@ -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 []

View File

@ -3,7 +3,7 @@ from enum import Enum, auto
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
@ -33,7 +33,7 @@ class MenuSelection:
return self.value # type: ignore
class Menu(TerminalMenu):
class Menu(TerminalMenu): # type: ignore[misc]
_menu_is_active: bool = False
@staticmethod

View File

@ -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

View File

@ -80,7 +80,7 @@ class MenuItemGroup:
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

View File

@ -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
@ -12,7 +12,7 @@ from archinstall import locale
from archinstall import info, debug
if TYPE_CHECKING:
_: Any
_: Callable[[str], str]
def ask_user_questions() -> None:

View File

@ -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
@ -10,7 +10,7 @@ from archinstall import interactions
from archinstall.default_profiles.minimal import MinimalProfile
if TYPE_CHECKING:
_: Any
_: Callable[[str], str]
def perform_installation(mountpoint: Path) -> None:

View File

@ -1,20 +0,0 @@
[mypy]
python_version = 3.11
follow_imports = silent
check_untyped_defs = True
strict_equality = True
warn_unused_configs = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
warn_unreachable = True
extra_checks = True
files = examples/
exclude = (?x)(
^archinstall)

View File

@ -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"]