typecheck: add --check-untyped-defs and fix some associated type errors

This commit is contained in:
InsanePrawn 2022-11-09 20:06:35 +01:00
parent c46cd0cd4f
commit a8e8ddc4b4
4 changed files with 15 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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