diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2010-10-16 09:17:39 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2010-11-23 17:02:58 (GMT) |
commit | 2244a06586e2150f40a14d7742fcc32f947dac81 (patch) | |
tree | 3567969bc41d4e31708caa834d1504fdc416876c | |
parent | 7e258fb45424f6f6fa3115e96c02a5d9d59f1d2a (diff) |
sugar.dispatch.saferef: don't use assert for critical code paths
assert a debugging tool, not meant to guard critical code paths. See e.g.
"Language Reference" section 6.3, first paragraph:
> Assert statements are a convenient way to insert debugging assertions into a
> program:
The same section also explains that enabling optimization will cause assert
statements not to be evaluated.
Reviewed-by: James Cameron <quozl@laptop.org>
Acked-by: Simon Schampijer <simon@laptop.org>
-rw-r--r-- | src/sugar/dispatch/saferef.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/sugar/dispatch/saferef.py b/src/sugar/dispatch/saferef.py index b0ceef9..655f9a1 100644 --- a/src/sugar/dispatch/saferef.py +++ b/src/sugar/dispatch/saferef.py @@ -23,11 +23,12 @@ def safeRef(target, onDelete = None): if target.im_self is not None: # Turn a bound method into a BoundMethodWeakref instance. # Keep track of these instances for lookup by disconnect(). - assert hasattr(target, 'im_func'), """safeRef target %r has im_self, but no im_func, don't know how to create reference"""%( target,) - reference = get_bound_method_weakref( - target=target, - onDelete=onDelete - ) + if not hasattr(target, 'im_func'): + raise TypeError("safeRef target %r has im_self, but no" + " im_func, don't know how to create reference" % + (target, )) + reference = get_bound_method_weakref(target=target, + onDelete=onDelete) return reference if callable(onDelete): return weakref.ref(target, onDelete) |