Remove useless returns and variables

* tiramisu/option.py (Multi.__setitem__): Do not returns.
  (Multi.append): Ditoo.
  Remove useless "ret" variable.
  (Multi._setvalue): Ditoo.
  (Multi.pop): Do not set "ret" to None, raise if "ret" is not in "locals()"
  (Multi._pop): Avoid useless "oldvalue" variable.
This commit is contained in:
Daniel Dehennin 2013-01-30 09:19:48 +01:00
parent f267073e0d
commit deaa0942ff

View File

@ -68,7 +68,7 @@ class Multi(list):
super(Multi, self).__init__(lst)
def __setitem__(self, key, value):
return self._setvalue(value, key, who=settings.get_owner())
self._setvalue(value, key, who=settings.get_owner())
def append(self, value, add_master=True):
"""the list value can be updated (appened)
@ -82,20 +82,16 @@ class Multi(list):
raise IndexError("in a group with a master, you mustn't add "
"a value in a slave's Multi value")
except TypeError:
return self._setvalue(value, who=settings.get_owner())
self._setvalue(value, who=settings.get_owner())
multis = []
ret = None
for name, multi in self.config:
multis.append(multi)
for multi in multis:
if master == multi.opt._name:
if add_master:
ret = multi._setvalue(value, who=settings.get_owner())
else:
ret = value
multi._setvalue(value, who=settings.get_owner())
else:
multi._append_default()
return ret
def _append_default(self):
default_value = self.opt.getdefault_multi()
@ -107,22 +103,24 @@ class Multi(list):
raise ConfigError("invalid value {0} "
"for option {1}".format(str(value), self.opt._name))
oldvalue = list(self)
ret = None
if key is None:
ret = super(Multi, self).append(value)
super(Multi, self).append(value)
else:
ret = super(Multi, self).__setitem__(key, value)
super(Multi, self).__setitem__(key, value)
if who != None:
if not isinstance(who, owners.Owner):
raise TypeError("invalid owner {0} for the value {1}".format(
str(who), str(value)))
self.opt.setowner(self.config, getattr(owners, who))
self.config._cfgimpl_previous_values[self.opt._name] = oldvalue
return ret
def pop(self, key):
"""the list value can be updated (poped)
only if the option is a master
:param key: index of the element to pop
:return: the requested element
"""
try:
master = self.config._cfgimpl_descr.get_master_name()
@ -133,7 +131,6 @@ class Multi(list):
return self._pop(key)
multis = []
ret = None
for name, multi in self.config:
multis.append(multi)
for multi in multis:
@ -147,13 +144,14 @@ class Multi(list):
if len(multi.opt.getdefault()) >= len(multi):
change_who = True
multi._pop(key, change_who=change_who)
if ret not in locals():
raise ConfigError('Unexpected multi pop error: ret must be defined')
return ret
def _pop(self, key, change_who=True):
oldvalue = list(self)
if change_who:
self.opt.setowner(self.config, settings.get_owner())
self.config._cfgimpl_previous_values[self.opt._name] = oldvalue
self.config._cfgimpl_previous_values[self.opt._name] = list(self)
return super(Multi, self).pop(key)
# ____________________________________________________________
#