Skip to content

Commit

Permalink
Do not store function name in __init__
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtackaberry committed Jan 19, 2012
1 parent 92350f7 commit 5fbf322
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/callable.py
Expand Up @@ -125,9 +125,7 @@ def __init__(self, func, *args, **kwargs):
:param kwargs: keyword arguments to be passed to func when invoked :param kwargs: keyword arguments to be passed to func when invoked
""" """
super(Callable, self).__init__() super(Callable, self).__init__()
assert(callable(func))
self._func = func self._func = func
self._func_name = str(func)
self._args = args self._args = args
self._kwargs = kwargs self._kwargs = kwargs
self._ignore_caller_args = False self._ignore_caller_args = False
Expand Down Expand Up @@ -219,8 +217,8 @@ def __call__(self, *args, **kwargs):
The wrapped callable's return value is returned. The wrapped callable's return value is returned.
""" """
cb = self._get_func() cb = self._get_func()
if not cb: if cb is None:
raise CallableError('The Callable (%s) has become invalid.' % self._func_name) raise CallableError('attempting to invoke an invalid callable')


cb_args, cb_kwargs = self._merge_args(args, kwargs) cb_args, cb_kwargs = self._merge_args(args, kwargs)
return cb(*cb_args, **cb_kwargs) return cb(*cb_args, **cb_kwargs)
Expand Down

0 comments on commit 5fbf322

Please sign in to comment.