Add default option to getOriginal. This eliminates some double lookups and simplifies the code.
This commit is contained in:
@@ -128,7 +128,7 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
if key in self.__intermediary:
|
||||
del self.__intermediary[key]
|
||||
|
||||
def getOriginal(self, key):
|
||||
def getOriginal(self, key, default=None):
|
||||
|
||||
if self.overrides:
|
||||
val = self.overrides.get(key, None)
|
||||
@@ -139,6 +139,9 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
if self.original:
|
||||
val = self.original.get(key, None)
|
||||
|
||||
if val is None and val != default:
|
||||
val = default
|
||||
|
||||
return val.value if hasattr(val, "value") else val
|
||||
|
||||
def __setitem__(self, key, val):
|
||||
@@ -216,7 +219,7 @@ class ModifiedAttributeDict(collections.MutableMapping):
|
||||
|
||||
val = self.__intermediary.get(key,
|
||||
self.__preAssigns.get(key,
|
||||
self.getOriginal(key) if key in self.original else default
|
||||
self.getOriginal(key, default)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1043,7 +1043,7 @@ class ItemAffectedBy(wx.Panel):
|
||||
container = {}
|
||||
for attrName in attributes.iterAfflictions():
|
||||
# if value is 0 or there has been no change from original to modified, return
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName) or 0):
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName, 0)):
|
||||
continue
|
||||
|
||||
for fit, afflictors in attributes.getAfflictions(attrName).iteritems():
|
||||
@@ -1170,7 +1170,7 @@ class ItemAffectedBy(wx.Panel):
|
||||
container = {}
|
||||
for attrName in attributes.iterAfflictions():
|
||||
# if value is 0 or there has been no change from original to modified, return
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName) or 0):
|
||||
if attributes[attrName] == (attributes.getOriginal(attrName, 0)):
|
||||
continue
|
||||
|
||||
for fit, afflictors in attributes.getAfflictions(attrName).iteritems():
|
||||
|
||||
Reference in New Issue
Block a user