Checking Signature of Function Parameter

Chris Angelico rosuav at gmail.com
Sun Aug 28 17:31:52 EDT 2011


On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks <jehugaleahsa at 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



More information about the Python-list mailing list