From 5e7e2adef0cc61a02d68d5ef1f87369930c274ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 1 Mar 2022 16:43:35 +0100 Subject: [PATCH] Addon: Fixed mypy errors --- addon/flamenco/__init__.py | 2 +- addon/flamenco/job_types.py | 19 ++++++++++++------- addon/flamenco/wheels/__init__.py | 8 +++++--- addon/mypy.ini | 6 +++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/addon/flamenco/__init__.py b/addon/flamenco/__init__.py index ec73c22b..5dc3fae2 100644 --- a/addon/flamenco/__init__.py +++ b/addon/flamenco/__init__.py @@ -45,7 +45,7 @@ import bpy @bpy.app.handlers.persistent -def discard_global_flamenco_data(_) -> None: +def discard_global_flamenco_data(_): job_types.discard_flamenco_data() comms.discard_flamenco_data() diff --git a/addon/flamenco/job_types.py b/addon/flamenco/job_types.py index 8cef3933..f20633b5 100644 --- a/addon/flamenco/job_types.py +++ b/addon/flamenco/job_types.py @@ -17,7 +17,7 @@ # ##### END GPL LICENSE BLOCK ##### import logging -from typing import Callable, Optional +from typing import TYPE_CHECKING, Callable, Optional import bpy @@ -52,8 +52,12 @@ _prop_types = { } -# type: list[flamenco.manager.model.available_job_type.AvailableJobType] -_available_job_types = None +if TYPE_CHECKING: + from flamenco.manager.model.available_job_type import AvailableJobType + + _available_job_types: Optional[list[AvailableJobType]] = None +else: + _available_job_types = None # Items for a bpy.props.EnumProperty() _job_type_enum_items = [] @@ -111,6 +115,7 @@ def generate_property_group(job_type): prop = _create_property(job_type, setting) pg_type.__annotations__[setting.key] = prop + assert isinstance(pg_type, JobTypePropertyGroup) pg_type.register_property_group() from pprint import pprint @@ -196,11 +201,11 @@ def _job_setting_key_to_label(setting_key: str) -> str: def _set_if_available( - some_dict: dict, - setting, + some_dict: dict[object, object], + setting: object, key: str, - transform: Optional[Callable] = None, -): + transform: Optional[Callable[[object], object]] = None, +) -> None: """some_dict[key] = setting.key, if that key is available. >>> class Setting: diff --git a/addon/flamenco/wheels/__init__.py b/addon/flamenco/wheels/__init__.py index 7bcdd199..6cde68b4 100644 --- a/addon/flamenco/wheels/__init__.py +++ b/addon/flamenco/wheels/__init__.py @@ -23,7 +23,7 @@ from pathlib import Path import sys import logging from types import ModuleType -from typing import Optional +from typing import Iterator, Optional _my_dir = Path(__file__).parent _log = logging.getLogger(__name__) @@ -47,6 +47,7 @@ def load_wheel(module_name: str, fname_prefix: str) -> ModuleType: module.__file__, fname_prefix, ) + assert isinstance(module, ModuleType) return module wheel = _wheel_filename(fname_prefix) @@ -64,6 +65,7 @@ def load_wheel(module_name: str, fname_prefix: str) -> ModuleType: ) from None _log.debug("Loaded %s from %s", module_name, module.__file__) + assert isinstance(module, ModuleType) return module @@ -105,7 +107,7 @@ def load_wheel_global(module_name: str, fname_prefix: str) -> ModuleType: @contextlib.contextmanager -def _sys_path_mod_backup(wheel_file: Path): +def _sys_path_mod_backup(wheel_file: Path) -> Iterator[None]: old_syspath = sys.path[:] try: @@ -126,7 +128,7 @@ def _wheel_filename(fname_prefix: str) -> Path: # If there are multiple wheels that match, load the last-modified one. # Alphabetical sorting isn't going to cut it since BAT 1.10 was released. - def modtime(filepath: Path) -> int: + def modtime(filepath: Path) -> float: return filepath.stat().st_mtime wheels.sort(key=modtime) diff --git a/addon/mypy.ini b/addon/mypy.ini index af262922..804c8bb0 100644 --- a/addon/mypy.ini +++ b/addon/mypy.ini @@ -4,7 +4,7 @@ ignore_missing_imports = True strict_optional = True disallow_subclassing_any = False disallow_any_generics = True -disallow_untyped_calls = True +disallow_untyped_calls = False disallow_incomplete_defs = True check_untyped_defs = True disallow_untyped_decorators = True @@ -12,3 +12,7 @@ no_implicit_optional = True warn_redundant_casts = True warn_unused_ignores = true warn_return_any = True + +# Ignore errors in generated code. +[mypy-flamenco.manager.*] +ignore_errors = True