From 214e716a8fd3cc49703a4815d0028efd62f8596d Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Sun, 20 Mar 2022 14:54:20 +0100 Subject: [PATCH] Draft: Simplify using getattr instead of hasattr Using the default argument supported by getattr makes this code a bit simpler and probably (ever so slightly) faster. See https://forum.freecadweb.org/viewtopic.php?f=10&t=58611 for previous discussion. This is not an exhaustive change, these are just a few I encounted while working with the code. --- src/Mod/Draft/draftobjects/shape2dview.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Mod/Draft/draftobjects/shape2dview.py b/src/Mod/Draft/draftobjects/shape2dview.py index 5183da27ce..df08c6ab34 100644 --- a/src/Mod/Draft/draftobjects/shape2dview.py +++ b/src/Mod/Draft/draftobjects/shape2dview.py @@ -184,9 +184,8 @@ class Shape2DView(DraftObject): return nedges def execute(self,obj): - if hasattr(obj,"AutoUpdate"): - if not obj.AutoUpdate: - return True + if not getattr(obj,"AutoUpdate", True): + return True import Part, DraftGeomUtils obj.positionBySupport() pl = obj.Placement @@ -215,7 +214,7 @@ class Shape2DView(DraftObject): if getattr(obj,"VisibleOnly",True): objs = gui_utils.remove_hidden(objs) shapes = [] - if hasattr(obj,"FuseArch") and obj.FuseArch: + if getattr(obj,"FuseArch", False): shtypes = {} for o in objs: if utils.get_type(o) in ["Wall","Structure"]: