Checking Signature of Function Parameter
ian.g.kelly at gmail.com
Mon Aug 29 02:40:22 CEST 2011
On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks <jehugaleahsa at gmail.com> wrote:
> I am trying to write an algorithms library in Python. Most of the
> functions will accept functions as parameters. For instance, there is
> a function called any:
> def any(source, predicate):
> for item in source:
> if predicate(item):
> return true;
> return false;
Perhaps not the best name, since there is already a built-in called
"any" that would be masked by this. Using the built-in, "any(source,
predicate)" would be written as "any(predicate(x) for x in source)"
> I guess my concern is mostly with the delayed exceptions. It is hard
> to find the source of an error when it doesn't happen immediately. I
> am writing this library so all of the calls can be chained together
> (composed). If this nesting gets really deep, finding the source is
> hard to do, even with a good debugger.
Agreed that there are cases where it is useful to do this. But there
is no delayed execution in the example you've given, so the exceptions
will happen immediately (or at least, within the same stack frame).
The stack traces will still come from the "any" function and will look
basically the same as the stack traces you'll get from raising the
exceptions by hand.
More information about the Python-list