Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12365

Re: Checking Signature of Function Parameter

References <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-08-28 18:40 -0600
Subject Re: Checking Signature of Function Parameter
Newsgroups comp.lang.python
Message-ID <mailman.523.1314578453.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Aug 28, 2011 at 3:20 PM, Travis Parks <jehugaleahsa@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.

HTH,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-28 14:20 -0700
  Re: Checking Signature of Function Parameter Chris Angelico <rosuav@gmail.com> - 2011-08-29 07:31 +1000
    Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-28 17:20 -0700
      Re: Checking Signature of Function Parameter Chris Angelico <rosuav@gmail.com> - 2011-08-29 10:27 +1000
  Re: Checking Signature of Function Parameter Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-28 18:40 -0600
  Re: Checking Signature of Function Parameter Chris Rebert <clp2@rebertia.com> - 2011-08-28 18:21 -0700
  Re: Checking Signature of Function Parameter Nobody <nobody@nowhere.com> - 2011-08-29 07:30 +0100
    Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-29 09:45 -0700
      Re: Checking Signature of Function Parameter Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-29 11:42 -0600
        Re: Checking Signature of Function Parameter Travis Parks <jehugaleahsa@gmail.com> - 2011-08-29 11:04 -0700
          Re: Checking Signature of Function Parameter Ethan Furman <ethan@stoneleaf.us> - 2011-08-29 16:36 -0700

csiph-web