From e9cdd47a03b1d30524ed46ebf2254935a3c59fa9 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 14 Sep 2018 12:38:16 +0200 Subject: [PATCH] Fix types of getGlobalContainerStack call results We know in these places that there must be a global stack at this point. So to hide the type error we'll cast it here. Of course, the danger in this is that someone might call this function that doesn't know about this requirement and calls it when there is potentially no global stack yet. Hopefully they'll discover this crash when that happens then. --- cura/Settings/ExtruderManager.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cura/Settings/ExtruderManager.py b/cura/Settings/ExtruderManager.py index 230759e775..26a030ffde 100755 --- a/cura/Settings/ExtruderManager.py +++ b/cura/Settings/ExtruderManager.py @@ -15,12 +15,11 @@ from UM.Settings.SettingFunction import SettingFunction from UM.Settings.ContainerStack import ContainerStack from UM.Settings.PropertyEvaluationContext import PropertyEvaluationContext -from typing import Optional, TYPE_CHECKING, Dict, List, Any +from typing import Any, cast, Dict, List, Optional, TYPE_CHECKING if TYPE_CHECKING: from cura.Settings.ExtruderStack import ExtruderStack from cura.Settings.GlobalStack import GlobalStack - from UM.Scene.SceneNode import SceneNode ## Manages all existing extruder stacks. @@ -377,7 +376,7 @@ class ExtruderManager(QObject): # If no extruder has the value, the list will contain the global value. @staticmethod def getExtruderValues(key: str) -> List[Any]: - global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() + global_stack = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()) #We know that there must be a global stack by the time you're requesting setting values. result = [] for extruder in ExtruderManager.getInstance().getActiveExtruderStacks(): @@ -412,7 +411,7 @@ class ExtruderManager(QObject): # If no extruder has the value, the list will contain the global value. @staticmethod def getDefaultExtruderValues(key: str) -> List[Any]: - global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() + global_stack = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()) #We know that there must be a global stack by the time you're requesting setting values. context = PropertyEvaluationContext(global_stack) context.context["evaluate_from_container_index"] = 1 # skip the user settings container context.context["override_operators"] = { @@ -479,7 +478,7 @@ class ExtruderManager(QObject): value = value(extruder) else: # Just a value from global. - value = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack().getProperty(key, "value") + value = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()).getProperty(key, "value") return value @@ -508,7 +507,7 @@ class ExtruderManager(QObject): if isinstance(value, SettingFunction): value = value(extruder, context = context) else: # Just a value from global. - value = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack().getProperty(key, "value", context = context) + value = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()).getProperty(key, "value", context = context) return value @@ -521,7 +520,7 @@ class ExtruderManager(QObject): # \return The effective value @staticmethod def getResolveOrValue(key: str) -> Any: - global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() + global_stack = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()) resolved_value = global_stack.getProperty(key, "value") return resolved_value @@ -535,7 +534,7 @@ class ExtruderManager(QObject): # \return The effective value @staticmethod def getDefaultResolveOrValue(key: str) -> Any: - global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() + global_stack = cast(GlobalStack, cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()) context = PropertyEvaluationContext(global_stack) context.context["evaluate_from_container_index"] = 1 # skip the user settings container context.context["override_operators"] = {