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.
This commit is contained in:
Matthijs Kooijman
2022-03-20 14:54:20 +01:00
parent 52e7dafedb
commit b7c94992c9

View File

@@ -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"]: