Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'raised': 0.07; 'etc).': 0.09; 'exceptions': 0.09; 'loop.': 0.09; 'none:': 0.09; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; 'subject:Function': 0.09; 'am,': 0.12; 'callable,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable,': 0.16; 'parks': 0.16; 'subject:Checking': 0.16; 'travis': 0.16; 'worried': 0.16; 'mon,': 0.16; 'wrote:': 0.16; 'otherwise,': 0.19; '(which': 0.19; 'header :In-Reply-To:1': 0.22; 'etc,': 0.23; 'aug': 0.24; 'ignore': 0.26; 'code.': 0.26; 'raise': 0.28; 'problem': 0.28; 'message- id:@mail.gmail.com': 0.29; "won't": 0.29; 'strings,': 0.30; 'error': 0.32; 'source': 0.33; "isn't": 0.33; 'it.': 0.33; 'to:addr:python-list': 0.33; 'received:209.85.160': 0.35; 'lists,': 0.35; 'something': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; 'your': 0.61; 'carry': 0.62; '29,': 0.67; 'failure': 0.73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=zj/5sznCVd8TlmkVkSsG2idU4KJrj8OZszK8OSysa/k=; b=Xn1AFfWDCbKJAFuzxfk2w6ndL3EVZywW2I9pU0j4IzlVKSd54n8jwxzkyTGQZR9tYY 1ReJhasWKIFPP8wWrI3A1taPnhoph63zpQmmOGcdY7TSRBZxSuOvYqLUXhPpVPFsz0OQ jpHAVpKORHC3Pv4GsGgvF1rCUvuiTNvpVf4pM= MIME-Version: 1.0 In-Reply-To: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> References: <5176c3dc-9270-46fe-a4d3-9dc2e9e97da5@q2g2000vbz.googlegroups.com> Date: Mon, 29 Aug 2011 07:31:52 +1000 Subject: Re: Checking Signature of Function Parameter From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314567115 news.xs4all.nl 2493 [2001:888:2000:d::a6]:37596 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12354 On Mon, Aug 29, 2011 at 7:20 AM, Travis Parks 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