From a8e8ddc4b4cb01e1caee3de2aeb8b04aa1e869c0 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Wed, 9 Nov 2022 20:06:35 +0100 Subject: [PATCH] typecheck: add --check-untyped-defs and fix some associated type errors --- chroot/abstract.py | 4 ++-- config/test_config.py | 14 +++++++++++--- packages/cli.py | 2 +- typecheck.sh | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/chroot/abstract.py b/chroot/abstract.py index f0671e2..9c10d83 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -4,7 +4,7 @@ import os import subprocess from copy import deepcopy from shlex import quote as shell_quote -from typing import ClassVar, Protocol, Union, Optional, Mapping +from typing import ClassVar, Iterable, Protocol, Union, Optional, Mapping from uuid import uuid4 from config.state import config @@ -179,7 +179,7 @@ class Chroot(AbstractChroot): self.active_mounts.remove(relative_path) return result - def umount_many(self, relative_paths: list[str]): + def umount_many(self, relative_paths: Iterable[str]): # make sure paths start with '/'. Important: also copies the collection and casts to list, which will be sorted! mounts = [make_abs_path(path) for path in relative_paths] mounts.sort(reverse=True) diff --git a/config/test_config.py b/config/test_config.py index 4856c11..6854cc8 100644 --- a/config/test_config.py +++ b/config/test_config.py @@ -5,7 +5,7 @@ import pickle import toml from tempfile import mktemp, gettempdir as get_system_tempdir -from typing import Optional +from typing import Any, Optional from config.profile import PROFILE_DEFAULTS from config.scheme import Config, Profile @@ -154,8 +154,16 @@ def test_config_save_modified(configstate_emptyfile: ConfigStateHolder): compare_to_defaults(load_toml_file(get_path_from_stateholder(c)), defaults_modified) +def get_config_scheme(data: dict[str, Any], validate=True, allow_incomplete=False) -> Config: + """ + helper func to ignore a false type error. + for some reason, mypy argues about DataClass.fromDict() instead of Config.fromDict() here + """ + return Config.fromDict(data, validate=validate, allow_incomplete=allow_incomplete) # type: ignore[call-arg] + + def test_config_scheme_defaults(): - c = Config.fromDict(CONFIG_DEFAULTS, validate=True, allow_incomplete=False) + c = get_config_scheme(CONFIG_DEFAULTS, validate=True, allow_incomplete=False) assert c compare_to_defaults(c) @@ -164,7 +172,7 @@ def test_config_scheme_modified(): modifications = {'wrapper': {'type': 'none'}, 'build': {'crossdirect': False}} assert set(modifications.keys()).issubset(CONFIG_DEFAULTS.keys()) d = {section_name: (section | modifications.get(section_name, {})) for section_name, section in CONFIG_DEFAULTS.items()} - c = Config.fromDict(d, validate=True, allow_incomplete=False) + c = get_config_scheme(d, validate=True, allow_incomplete=False) assert c assert c.build.crossdirect is False assert c.wrapper.type == 'none' diff --git a/packages/cli.py b/packages/cli.py index 042aae6..ff924c2 100644 --- a/packages/cli.py +++ b/packages/cli.py @@ -224,7 +224,7 @@ def cmd_check(paths): is_git_package = True required_arches = '' - provided_arches = [] + provided_arches: list[str] = [] mode_key = '_mode' nodeps_key = '_nodeps' diff --git a/typecheck.sh b/typecheck.sh index 54117aa..19b17c4 100755 --- a/typecheck.sh +++ b/typecheck.sh @@ -1,2 +1,2 @@ #!/bin/bash -git ls-files \*.py | sort -u | xargs mypy --pretty --show-error-codes --install-types --ignore-missing-imports "$@" +git ls-files \*.py | sort -u | xargs mypy --pretty --show-error-codes --check-untyped-defs --install-types --ignore-missing-imports "$@"