From 5fbf322afc5d44e429ab61a5f65ca46dddb07233 Mon Sep 17 00:00:00 2001 From: Jason Tackaberry Date: Wed, 18 Jan 2012 19:12:58 -0500 Subject: [PATCH] Do not store function name in __init__ This optimizes Callable instantiation when str(func) is expensive (like in the case of InProgress objects). This was added to improve debugging for WeakCallables, but the use-cases for a traceback being insufficient are few so we'll take the optimization win. --- src/callable.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/callable.py b/src/callable.py index 490fd36..5ab9ea6 100644 --- a/src/callable.py +++ b/src/callable.py @@ -125,9 +125,7 @@ def __init__(self, func, *args, **kwargs): :param kwargs: keyword arguments to be passed to func when invoked """ super(Callable, self).__init__() - assert(callable(func)) self._func = func - self._func_name = str(func) self._args = args self._kwargs = kwargs self._ignore_caller_args = False @@ -219,8 +217,8 @@ def __call__(self, *args, **kwargs): The wrapped callable's return value is returned. """ cb = self._get_func() - if not cb: - raise CallableError('The Callable (%s) has become invalid.' % self._func_name) + if cb is None: + raise CallableError('attempting to invoke an invalid callable') cb_args, cb_kwargs = self._merge_args(args, kwargs) return cb(*cb_args, **cb_kwargs)