From 5be9985e3b6faefd6036033948b66fc6e15a0b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 11 Mar 2022 11:18:21 +0100 Subject: [PATCH] Addon: fix Mypy errors --- addon/flamenco/comms.py | 8 +++++++- addon/flamenco/job_types.py | 33 +++++++++++++++++++++++++-------- addon/flamenco/preferences.py | 2 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/addon/flamenco/comms.py b/addon/flamenco/comms.py index fc716151..7290fc4b 100644 --- a/addon/flamenco/comms.py +++ b/addon/flamenco/comms.py @@ -3,12 +3,18 @@ # import logging +from typing import TYPE_CHECKING _flamenco_client = None _log = logging.getLogger(__name__) +if TYPE_CHECKING: + from flamenco.manager import ApiClient as _ApiClient +else: + _ApiClient = object -def flamenco_api_client(manager_url: str): + +def flamenco_api_client(manager_url: str) -> _ApiClient: """Returns an API client for communicating with a Manager.""" global _flamenco_client diff --git a/addon/flamenco/job_types.py b/addon/flamenco/job_types.py index 8a3531d8..52bde2d3 100644 --- a/addon/flamenco/job_types.py +++ b/addon/flamenco/job_types.py @@ -2,7 +2,7 @@ from inspect import isclass import logging -from typing import TYPE_CHECKING, Callable, Optional +from typing import TYPE_CHECKING, Callable, Optional, Union import bpy @@ -45,7 +45,9 @@ else: _available_job_types = None # Items for a bpy.props.EnumProperty() -_job_type_enum_items = [] +_job_type_enum_items: list[ + Union[tuple[str, str, str], tuple[str, str, str, int, int]] +] = [] _selected_job_type_propgroup: Optional[JobTypePropertyGroup] = None @@ -67,11 +69,13 @@ def fetch_available_job_types(api_client): # Remember the available job types. _available_job_types = response.job_types - - # Convert from API response type to list suitable for an EnumProperty. - _job_type_enum_items = [ - (job_type.name, job_type.label, "") for job_type in _available_job_types - ] + if _available_job_types is None: + _job_type_enum_items = [] + else: + # Convert from API response type to list suitable for an EnumProperty. + _job_type_enum_items = [ + (job_type.name, job_type.label, "") for job_type in _available_job_types + ] _job_type_enum_items.insert(0, ("", "Select a Job Type", "", 0, 0)) @@ -130,12 +134,25 @@ def _clear_job_type_propgroup(): _selected_job_type_propgroup = None -def active_job_type(window_manager: bpy.types.WindowManager): +if TYPE_CHECKING: + from flamenco.manager.model.available_job_type import ( + AvailableJobType as _AvailableJobType, + ) +else: + _AvailableJobType = object + + +def active_job_type( + window_manager: bpy.types.WindowManager, +) -> Optional[_AvailableJobType]: """Return the active job type. Returns a flamenco.manager.model.available_job_type.AvailableJobType, or None if there is none. """ + if _available_job_types is None: + return None + job_type_name = window_manager.flamenco_job_type for job_type in _available_job_types: if job_type.name == job_type_name: diff --git a/addon/flamenco/preferences.py b/addon/flamenco/preferences.py index ad45e633..06072654 100644 --- a/addon/flamenco/preferences.py +++ b/addon/flamenco/preferences.py @@ -37,7 +37,7 @@ def manager_url(context: bpy.types.Context) -> str: assert isinstance( prefs, FlamencoPreferences ), "Expected FlamencoPreferences, got %s instead" % (type(prefs)) - return prefs.manager_url + return str(prefs.manager_url) classes = (FlamencoPreferences,)