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


Groups > comp.lang.python > #12354

Re: Checking Signature of Function Parameter

References <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com>
Date 2011-08-29 07:31 +1000
Subject Re: Checking Signature of Function Parameter
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.517.1314567115.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks <jehugaleahsa@gmail.com> wrote:
>
> if source is None: raise ValueError("")
> if not isinstanceof(source, collections.iterable): raise TypeError("")
> if not callable(predicate): raise TypeError("")
>

Easier: Just ignore the possibilities of failure and carry on with
your code. If the source isn't iterable, you'll get an error raised by
the for loop. If the predicate's not callable, you'll get an error
raised when you try to call it. The only consideration you might need
to deal with is that the predicate's not callable, and only if you're
worried that consuming something from your source would be a problem
(which it won't be with the normal iterables - strings, lists, etc,
etc). Otherwise, just let the exceptions be raised!

ChrisA

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