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
1 changed files with 12 additions and 14 deletions

View File

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