Addon: Fixed mypy errors

This commit is contained in:
Sybren A. Stüvel 2022-03-01 16:43:35 +01:00
parent 616784df0a
commit 5e7e2adef0
4 changed files with 23 additions and 12 deletions

View File

@ -45,7 +45,7 @@ import bpy
@bpy.app.handlers.persistent @bpy.app.handlers.persistent
def discard_global_flamenco_data(_) -> None: def discard_global_flamenco_data(_):
job_types.discard_flamenco_data() job_types.discard_flamenco_data()
comms.discard_flamenco_data() comms.discard_flamenco_data()

View File

@ -17,7 +17,7 @@
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
import logging import logging
from typing import Callable, Optional from typing import TYPE_CHECKING, Callable, Optional
import bpy import bpy
@ -52,8 +52,12 @@ _prop_types = {
} }
# type: list[flamenco.manager.model.available_job_type.AvailableJobType] if TYPE_CHECKING:
_available_job_types = None 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() # Items for a bpy.props.EnumProperty()
_job_type_enum_items = [] _job_type_enum_items = []
@ -111,6 +115,7 @@ def generate_property_group(job_type):
prop = _create_property(job_type, setting) prop = _create_property(job_type, setting)
pg_type.__annotations__[setting.key] = prop pg_type.__annotations__[setting.key] = prop
assert isinstance(pg_type, JobTypePropertyGroup)
pg_type.register_property_group() pg_type.register_property_group()
from pprint import pprint from pprint import pprint
@ -196,11 +201,11 @@ def _job_setting_key_to_label(setting_key: str) -> str:
def _set_if_available( def _set_if_available(
some_dict: dict, some_dict: dict[object, object],
setting, setting: object,
key: str, key: str,
transform: Optional[Callable] = None, transform: Optional[Callable[[object], object]] = None,
): ) -> None:
"""some_dict[key] = setting.key, if that key is available. """some_dict[key] = setting.key, if that key is available.
>>> class Setting: >>> class Setting:

View File

@ -23,7 +23,7 @@ from pathlib import Path
import sys import sys
import logging import logging
from types import ModuleType from types import ModuleType
from typing import Optional from typing import Iterator, Optional
_my_dir = Path(__file__).parent _my_dir = Path(__file__).parent
_log = logging.getLogger(__name__) _log = logging.getLogger(__name__)
@ -47,6 +47,7 @@ def load_wheel(module_name: str, fname_prefix: str) -> ModuleType:
module.__file__, module.__file__,
fname_prefix, fname_prefix,
) )
assert isinstance(module, ModuleType)
return module return module
wheel = _wheel_filename(fname_prefix) wheel = _wheel_filename(fname_prefix)
@ -64,6 +65,7 @@ def load_wheel(module_name: str, fname_prefix: str) -> ModuleType:
) from None ) from None
_log.debug("Loaded %s from %s", module_name, module.__file__) _log.debug("Loaded %s from %s", module_name, module.__file__)
assert isinstance(module, ModuleType)
return module return module
@ -105,7 +107,7 @@ def load_wheel_global(module_name: str, fname_prefix: str) -> ModuleType:
@contextlib.contextmanager @contextlib.contextmanager
def _sys_path_mod_backup(wheel_file: Path): def _sys_path_mod_backup(wheel_file: Path) -> Iterator[None]:
old_syspath = sys.path[:] old_syspath = sys.path[:]
try: try:
@ -126,7 +128,7 @@ def _wheel_filename(fname_prefix: str) -> Path:
# If there are multiple wheels that match, load the last-modified one. # 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. # 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 return filepath.stat().st_mtime
wheels.sort(key=modtime) wheels.sort(key=modtime)

View File

@ -4,7 +4,7 @@ ignore_missing_imports = True
strict_optional = True strict_optional = True
disallow_subclassing_any = False disallow_subclassing_any = False
disallow_any_generics = True disallow_any_generics = True
disallow_untyped_calls = True disallow_untyped_calls = False
disallow_incomplete_defs = True disallow_incomplete_defs = True
check_untyped_defs = True check_untyped_defs = True
disallow_untyped_decorators = True disallow_untyped_decorators = True
@ -12,3 +12,7 @@ no_implicit_optional = True
warn_redundant_casts = True warn_redundant_casts = True
warn_unused_ignores = true warn_unused_ignores = true
warn_return_any = True warn_return_any = True
# Ignore errors in generated code.
[mypy-flamenco.manager.*]
ignore_errors = True