From de3d1f4a22b543c7e306ce85b081c7609f482128 Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 21 Sep 2012 00:15:04 +0200 Subject: [PATCH] Minor adjustment to the __contains__ cache of cmdsets. --- src/commands/cmdset.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/commands/cmdset.py b/src/commands/cmdset.py index c434796950..9e52f41460 100644 --- a/src/commands/cmdset.py +++ b/src/commands/cmdset.py @@ -14,7 +14,6 @@ See CmdHandler for practical examples on how to apply cmdsets together to create interesting in-game effects. """ -import copy from django.utils.translation import ugettext as _ from src.utils.utils import inherits_from, is_iter __all__ = ("CmdSet",) @@ -225,10 +224,8 @@ class CmdSet(object): Returns True if this cmdset contains the given command (as defined by command name and aliases). This allows for things like 'if cmd in cmdset' """ - # optimization test - try: - return self._contains_cache[othercmd] - except KeyError: + ret = self._contains_cache.get(othercmd) + if ret == None: ret = othercmd in self.commands self._contains_cache[othercmd] = ret return ret @@ -326,7 +323,7 @@ class CmdSet(object): # an infinite loop (adding cmdset to itself somehow) try: cmd = self._instantiate(cmd) - except RuntimeError, e: + except RuntimeError: string = "Adding cmdset %(cmd)s to %(class)s lead to an infinite loop. When adding a cmdset to another, " string += "make sure they are not themself cyclically added to the new cmdset somewhere in the chain." raise RuntimeError(_(string) % {"cmd":cmd, "class":self.__class__})